[转]SQL Server与Oracle 建表区别
在 SQL Server 中建表时的自增列:
Create table tmp1
(
id int identity(1,1) primary key,
....
)
而在 Oracle 中想要自增列,需要建触发器,如下所示:
Create table tmp1 ( id int primary key, field1 varchar2(100), field2 date ) create sequence tmp1_SEQ minvalue 1 maxvalue 999999999999999999999999 start with 1 increment by 1 cache 20; CREATE OR REPLACE TRIGGER "tmp1_ID_TRG" BEFORE INSERT ON tmp1 FOR EACH ROW BEGIN if inserting and :new.ID is NULL then SELECT tmp1_SEQ.nextval into :new.ID FROM DUAL; end if; END; create index IX_tmp1_ID on tmp1(ID); create index IX_tmp1_field1 on tmp1(field1);