例子:
基于开放人员需要,编写自动生成流水号的语句,如下:
| 代码如下 | 复制代码 |
|
create table detail(detailid varchar(50) primary key, proceedingsn varchar(50) not null,typesn int not null,truename varchar(50) not null,number varchar(50) not null, create trigger t_insert on detail alter table detail add constraint CK_DETAIL check (typesn=’1′ or typesn=’0′) alter table detail add constraint CK_DETAIL1 check (type=’1′ or type=’0′ or type=’2′) | |
例子2
| 代码如下 | 复制代码 |
|
--生成流水号 --创建测试表 create table test(id varchar(18), --流水号,日期(8位)+时间(4位)+流水号(4位) name varchar(10) --其他字段 ) go --创建生成流水号的触发器 create trigger t_insert on test INSTEAD OF insert as declare @id varchar(18),@id1 int,@head varchar(12) select * into #tb from inserted set @head=convert(varchar,getdate(),112)+replace(convert(varchar(5),getdate(),108),':','') select @id=max(id) from test where id like @head+'%' if @id is null set @id1=0 else set @id1=cast(substring(@id,13,4) as int) update #tb set @id1=@id1+1 ,id=@head+right('0000'+cast(@id1 as varchar),4) insert into test select * from #tb go --插入数据,进行测试 insert into test(name) select 'aa' union all select 'bb' union all select 'cc' --修改系统时间,再插入数据测试一次 insert into test(name) select 'aa' union all select 'bb' union all select 'cc' --显示测试结果 select * from test --删除测试环境 drop table test /*--测试结果 id name ------------------ ---------- 2004022720430001 aa 2004022720430002 bb 2004022720430003 cc 2004022720430004 aa 2004022720430005 bb 2004022720430006 cc (所影响的行数为 6 行) --*/ | |
例子3
需求背景
每执行一次方法,根据公式返回最新的流水号。
第一次使用时需要先插入一条数据,BizSeqValue 为流水起始号:A2014030000,Formula 为公式:A[yyyy][mm][c4],UseTime 为当前时间。
| 代码如下 | 复制代码 |
|
set @Year='' set @Month='' set @Day='' | |
我的世界国际版老版
我的世界国际版正式版是一款拥有超高自由度玩法是沙盒手游,经典
我的世界国际版完整版
我的世界国际服完整版是一款十分经典好玩的mc沙盒类游戏,在海
摩托车销售模拟器内置菜单中文版
摩托车出售模拟器,又名摩托车销售模拟器,这是一个以摩托车销售
船舶模拟2020最新版
船舶模拟2020是玩法非常有意思的模拟驾驶游戏,高清3d画质
油管主播的生活2内置菜单版
油管主播的生活2内置菜单版是一款模拟养成类游戏,在这里你将体