????Oracle?????sqlserver?????????????????У?????????sqlserver??????Ч???????????鷳????????????????????SEQUENCE?????????????????ɡ?

????CREATE SEQUENCE emp_sequence

????INCREMENT BY 1 -- ??????????????????1

????START WITH 1 -- ??1???????

????NOMAXvalue -- ????????????????????????MAXvalue ??????????????

????NOCYCLE -- ???????????

????NOCACHE ; --????????棬????????????????MAXvalue

??????????emp_sequence?????????CURRVAL??NEXTVAL??CURRVAL=???? sequence???????NEXTVAL=????sequence?????????? sequence ???

???????磺

????emp_sequence.CURRVAL ??emp_sequence.NEXTVAL

???????????sequence??????

????????????????snapshot??view?? SELECT ???

????INSERT??????????

????NSERT????values??

????UPDATE ?? set??

???????

?????????NEXTVAL????????????????NEXTVAL?????????????????????????????????CURRVAL ?????????SEQUENCE???????????????NEXTVAL??????????????CURRVAL??????????????NEXTVAL????????? SEQUENCE????????????????????????????????NEXTVAL?????????????????

??????????cache???Oracle????????????????????Щsequence????????????Щ??cache?????????Oracle????????鵽cache?? ???cache?????????? ?????????????????down???shutdown abort)??cache?е?sequence???. ?????????create sequence???????nocache????????????

?????????????Sequence????????????????????alter??drop??

?????????????????С?????

--????????????
create sequence seqid
NOMAXvalue
start with 1
increment by 1
nocache
order;
--??????????
create or replace trigger tri_test_id
  before insert on mytable   --mytable?????????????е??
  for each row
declare
  nextid number;
begin
  IF :new.Id IS NULL or :new.Id=0 THEN   --id??????????????е?????
    select seqid.nextval
    into nextid
    from sys.dual;
    :new.Id:=nextid;
  end if;
end tri_test_id;