oracle 自動生成主鍵

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;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章