-- 创建表
create table items(
id int primary key,
name varchar(32) not null,
price int not null,
detail varchar(100),
pic varchar(512),
createtime date ); -- 创建序列
create sequence sq_items
-- 自增步长
increment by 1
-- 始值
start with 1
-- 没有最大值
nomaxvalue
-- 不循环
nocycle; --创建触发器,将序列与表的字段关联起来,并实现自增
create or replace trigger itmes_trig
before insert on items
for each row
declare
begin
select sq_items.nextval into :new.id from dual;
end items_trig; insert into items (name,price) values('lf',12);
insert into items (name,price) values('tl',22);
insert into items (name,price) values('lt',22);
select * from items;
05-20 08:08