日期:2014-05-17 浏览次数:20492 次
begin transaction
DECLARE @a INT
select @a=col from jishubiao
SELECT CONVERT(VARCHAR(8),GETDATE(),112)+RIGHT('00000'+LTRIM(@a),5)
update jishubiao set col=col+1
commit transaction
--如果数据是单条插入的,用函数,批量插入的,用 INSTEAD of 触发器
create TRIGGER trg_assign_key ON dbo.SQLText INSTEAD OF INSERT
AS
DECLARE @key AS INT
if @@rowcount = 0 RETURN;
select @key = isnull(max(SigNo),cast(convert(char(6),getdate(),12)+'000' as int))
from SQLText with (xlock,paglock) where SigNo > cast(convert(char(6),getdate(),12)+'000' as int)
INSERT INTO dbo.SQLText(SigNo,[Text],Caption)
SELECT @key + ROW_NUMBER() OVER(ORDER BY getdate()), [Text],Caption
FROM inserted
GO