来源:自学PHP网 时间:2015-04-16 10:51 作者: 阅读:次
[导读] 先创建一个序列表if exists (select 1 from sysindexes where id = object_id( TSysSequence ) and name...
先创建一个序列表 if exists (select 1 from sysindexeswhere id = object_id('TSysSequence') and name = 'In_SeName' and indid > 0 and indid < 255) drop index TSysSequence.In_SeName go if exists (select 1 from sysobjects where id = object_id('TSysSequence') and type = 'U') drop table TSysSequence go /*==============================================================*/ /* Table: TSysSequence */ /*==============================================================*/ create table TSysSequence ( SeName nvarchar(50) not null, Increment int not null default 1, CurVal bigint not null default 0 ) go if exists (select 1 from sys.extended_properties where major_id = object_id('TSysSequence') and minor_id = 0) begin declare @CurrentUser sysname select @CurrentUser = user_name() execute sp_dropextendedproperty 'MS_Description', 'user', @CurrentUser, 'table', 'TSysSequence' end select @CurrentUser = user_name() execute sp_addextendedproperty 'MS_Description', ' 模拟oracle序列 不允许用户维护,数据库初始化以后不允许任何人修改其中的值。 默认生成名称为“DID”和“SID”的两个序列,意义为“数据序列号”和“系统序列号”。', 'user', @CurrentUser, 'table', 'TSysSequence' go insert 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 1 update TSysSequence set @SeVal = CurVal + Increment, CurVal = CurVal + Increment where SeName = @SeName 使用方法 declare @ID1 int select @ID1 declare @ID2 int select @ID2 |
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com