標籤:varchar seq 傳統 phone not incr name min 最小
1.預設是用目前時間
create table test(id int,time date default sysdate);
2.自動產生guid
Oracle8i引入了SYS_GUID這個概念,它同Oracle管理員所使用的傳統的序列(sequence)相比具有諸多優勢。一個序列產生器只是簡單地建立從給定的起點開始的一系列整數值,而且它被用在選擇陳述式的時候自動地遞增該系列。
-根據資料庫設計說明書建立表--GOODScreate table goods1(gid number(11) primary key,gname varchar2(20) not null unique,gprice number(18,1) not null,gnum number(11) not null);--實現GOODS1表中主鍵自動產生(需要使用序列和觸發器)--為GOODS1表建立序列:產生唯一一系列的數create sequence goods_seqstart with 1 --從1開始increment by 1 --每次增1minvalue 1 --最小值maxvalue 999999999999999 --最大值nocycle --不迴圈取數cache 10; --緩衝--為GOODS1表建立觸發器,用於自動從序列取值給GOODS1表中GID賦值create trigger goods_triggerbefore insert on goods1 --觸發條件:在向GOODS1表中插入資料之前自動觸發此觸發器for each row --行級觸發器:插入的每一行資料都會觸發begin select goods_seq.nextval into :NEW.GID from dual;end;--向GOODS1表中插入測試資料INSERT INTO goods1(gname,gprice,gnum) VALUES(‘computer‘,3000,100);INSERT INTO goods1(gname,gprice,gnum) VALUES(‘computer2‘,3500,100);INSERT INTO goods1(gname,gprice,gnum) VALUES(‘iphone6‘,4000,200);INSERT INTO goods1(gname,gprice,gnum) VALUES(‘iphone6s‘,5000,300);commit;
oracle見表