1,创建数据库表:
create table t1(
tid number(3) primary key,
tname varchar(10) not null,
tsex varchar(4) not null,
tage number(2) not null,
tnative varchar(16) not null
)
2,创建自动增长序列:
create sequence t1_seq
mixvalue 1 //最小值
maxvalue 9999999999 //最大值
start with 1 //开始值
increment by 1 //增量
cache 20 //缓存量
3,创建触发器:
create or replace trigger t1_trg
2 before insert on t1 //往表(t1)添加值时发
3 for each row //检查每行
4 begin
5 select t1_seq.nextval into :new.tid from dual;//自动生成的字段
6 end;
4,提交:
insert into t1(tname,tsex,tage,tnative)values('刘晓明','女',20,'黑龙江');
commit;