[size=medium][b]1.创建表[/b][/size]
[size=medium][b]
2.创建序列[/b][/size]
[size=medium][b]3.创建触发器[/b][/size]
-- 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
);
[size=medium][b]
2.创建序列[/b][/size]
CREATE SEQUENCE SEQ_USERS_ID
INCREMENT BY 1 -- 每次加几个
START WITH 1 -- 从1开始计数
NOMAXVALUE -- 不设置最大值
NOCYCLE -- 一直累加,不循环
CACHE 10;
[size=medium][b]3.创建触发器[/b][/size]
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;