Oracle ID 自增代碼的詳細(xì)介紹
作者:佚名
Oracle ID 自增是一種新生的語言,我們可以看到很多的書籍和網(wǎng)上的相關(guān)資料對其的實際操作步驟都有詳細(xì)的介紹。本文章就是對Oracle ID 自增在一些資料中很少見的idea
本文主要是介紹Oracle ID 自增代碼, Oracle ID 自增是計算機(jī)的實際應(yīng)用中經(jīng)常使用的計算機(jī)語言,如果你對其相關(guān)的代碼感興趣的話,你就可以點(diǎn)擊以下的文章對其進(jìn)行了解,望你會有所收獲。
1.創(chuàng)建表
Sql代碼
- -- Create table
- create table USERS
- (
- ID NUMBER not null,
- USERNAME VARCHAR2(25),
- PASSWORD VARCHAR2(25),
- EMAIL VARCHAR2(50)
- )
- tablespace USERS
- pctfree 10
- initrans 1
- maxtrans 255
- storage
- (
- initial 64K
- minextents 1
- maxextents unlimited
- );
- -- Create/Recreate primary, unique and foreign key
constraints- alter table USERS
- add constraint ID primary key (ID)
- using index
- tablespace USERS
- pctfree 10
- initrans 2
- maxtrans 255
- storage
- (
- initial 64K
- minextents 1
- maxextents unlimited
- );
- -- Create table
- create table USERS
- (
- ID NUMBER not null,
- USERNAME VARCHAR2(25),
- PASSWORD VARCHAR2(25),
- EMAIL VARCHAR2(50)
- )
- tablespace USERS
- pctfree 10
- initrans 1
- maxtrans 255
- storage
- (
- initial 64K
- minextents 1
- maxextents unlimited
- );
- -- Create/Recreate primary, unique and foreign key constraints
- alter table USERS
- add constraint ID primary key (ID)
- using index
- tablespace USERS
- pctfree 10
- initrans 2
- maxtrans 255
- storage
- (
- initial 64K
- minextents 1
- maxextents unlimited
- );
2.創(chuàng)建序列
Sql代碼
- CREATE SEQUENCE SEQ_USERS_ID
- INCREMENT BY 1 -- 每次加幾個
- START WITH 1 -- 從1開始計數(shù)
- NOMAXVALUE -- 不設(shè)置最大值
- NOCYCLE -- 一直累加,不循環(huán)
- CACHE 10;
- CREATE SEQUENCE SEQ_USERS_ID
- INCREMENT BY 1 -- 每次加幾個
- START WITH 1 -- 從1開始計數(shù)
- NOMAXVALUE -- 不設(shè)置最大值
- NOCYCLE -- 一直累加,不循環(huán)
- CACHE 10;
3.創(chuàng)建觸發(fā)器
Sql代碼
- create or replace trigger TRI_USERS_ID
- before insert on users
- for each row
- declare
- -- local variables here
- begin
- SELECT SEQ_USERS_ID.NEXTVAL
- INTO :NEW.ID
- FROM DUAL;
- end TRI_USERS_ID;
- create or replace trigger TRI_USERS_ID
- before insert on users
- for each row
- declare
- -- local variables here
- begin
- SELECT SEQ_USERS_ID.NEXTVAL
- INTO :NEW.ID
- FROM DUAL;
- end TRI_USERS_ID;
- Oracle 11g Multimedia DICOM
以上就是對Oracle ID 自增的實際應(yīng)用的代碼 的介紹,望你會有所收獲。
【編輯推薦】
責(zé)任編輯:佚名
來源:
互聯(lián)網(wǎng)