添加数据库表自增列
1.创建数据库表
-- Create table
create table T_MOBILE_BRAND
(
ID NUMBER not null,
NAME VARCHAR2(200)
)
tablespace MASS_DATA
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 2M
next 2M
minextents 1
maxextents unlimited
pctincrease 0
);
-- Create/Recreate primary, unique and foreign key constraints
alter table T_MOBILE_BRAND
add constraint T_MOBILE_BRAND_PK primary key (ID)
using index
tablespace MASS_DATA
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 2M
next 2M
minextents 1
maxextents unlimited
pctincrease 0
);
2.创建Sequence
-- Create sequence
create sequence SEQ_BRAND_ID
minvalue 1
maxvalue 9999999999999999999999999999
start with 741
increment by 1
cache 20;
3.创建触发器
CREATE OR REPLACE TRIGGER ADD_BRAND_ID BEFORE
INSERT ON T_MOBILE_BRAND FOR EACH ROW
BEGIN
SELECT SEQ_BRAND_ID.NEXTVAL INTO :NEW.ID
FROM DUAL;
END;