MSSqlServer pseudo sequence
MSSqlServer pseudo sequence_mysql
Create a sequence table if exists (select 1 from sysindexeswhere id = object_id ('tsyssequence ') and name = 'in _ sename' and indid> 0and indid <255) drop index TSysSequence. in_SeNamegoif exists (select 1 from 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. export 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 ','
Simulate oracle sequence
User maintenance is not allowed, and no one is allowed to modify the value after database initialization.
By default, two sequences named "DID" and "SID" are generated, meaning "data serial number" and "system serial number ". ',
'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
Create a stored procedure to complete sequence usage
If exists (select 1 from sysobjectswhere id = object_id ('pgetsequencevalue') and type in ('P', 'PC') drop procedure into procedure PGetSequenceValue @ SeName nvarchar (50 ), @ SeVal bigint outasbeginif not exists (select 1 from TSysSequence where SeName = @ SeName) beginraiserror ('Sequence % s' does not exist, 16,1, @ SeName) returnendupdate TSysSequence set @ SeVal = CurVal + Increment, CurVal = CurVal + Increment where SeName = @ SeNameendgo
Usage
declare @ID1 intEXEC PGetSequenceValue 'SID',@ID1 OUTPUTselect @ID1declare @ID2 intEXEC PGetSequenceValue 'DID',@ID2 OUTPUTselect @ID2
The above is the content of the MSSqlServer pseudo sequence_mysql. For more information, see The PHP Chinese website (www.php1.cn )!