本文主要是介紹Oracle ID 自增代碼, Oracle ID 自增是計算機的實際應用中經常使用的計算機語言,如果你對其相關的代碼感興趣的話,你就可以點擊以下的文章對其進行了解,望你會有所收獲。
1.創建表
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.創建序列
Sql代碼
3.創建觸發器
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