MSSqlServer伪序列_MySQL
MSSqlServer伪序列_MySQL 先创建一个序列表if exists (select 1from sysindexeswhere id = object_id('TSysSequence')and name = 'In_SeName'and indid > 0and indid < 255)drop index TSysSequence.In_SeNamegoif exists (select 1from sysobjectswhere id = object_id('TSysSequence')and type = 'U')drop table TSysSequencego/*======================================*//* Table: TSysSequence *//*=======================================*/create table TSysSequence (SeName nvarchar(50) not null,Increment int not null default 1,CurVal bigint not null default 0)goif exists (select 1 from sys.extended_propertieswhere major_id = object_id('TSysSequence') and minor_id = 0)begindeclare @CurrentUser sysnameselect @CurrentUser = user_name()execute sp_dropextendedproperty 'MS_Description','user', @CurrentUser, 'table', 'TSysSequence'endselect @CurrentUser = user_name()execute sp_addextendedproperty 'MS_Description',' 模拟oracle序列 'user', @CurrentUser, 'table', 'TSysSequence'goinsert into TSysSequence (SeName,Increment,CurVal) values ('DID',1,0) ;insert into TSysSequence (SeName,Increment,CurVal) values ('SID',1,0) ;/*=======================================*//* Index: In_SeName *//*=======================================*/create unique index In_SeName on TSysSequence (SeName ASC)go 再创建一个存储过程完成序列的使用 if exists (select 1from sysobjectswhere id = object_id('PGetSequenceValue')and type in ('P','PC'))drop procedure PGetSequenceValuegocreate procedure PGetSequenceValue@SeName nvarchar(50),@SeVal bigint outasbeginif not exists(select 1 from TSysSequence where SeName = @SeName)beginraiserror('不存在序列%s',16,1,@SeName)returnendupdate TSysSequence set @SeVal = CurVal + Increment, CurVal = CurVal + Increment where SeName = @SeNameendgo 使用方法 declare @ID1 intEXEC PGetSequenceValue 'SID',@ID1 OUTPUTselect @ID1declare @ID2 intEXEC PGetSequenceValue 'DID',@ID2 OUTPUTselect @ID2 以上就是MSSqlServer伪序列_MySQL的内容, |