oracle見表

來源:互聯網
上載者:User

標籤: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見表

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.