触发器批量更新 用游标,一个一个处理
来源:程序员人生 发布时间:2014-03-30 10:57:37 阅读次数:2561次
网(LieHuo.Net)教程 触发器批量更新 用游标,一个一个处理,代码如下:
CREATE TRIGGER [dbo].[Up_T]
ON [dbo].[T1]
FOR UPDATE
AS
begin
if update(T1_1)
BEGIN
--用游标,一个一个处理
DECLARE @fID int
DECLARE tmpGoods CURSOR for select ID from deleted
OPEN tmpGoods
FETCH NEXT FROM tmpGoods into @fID
WHILE @@FETCH_STATUS=0
BEGIN
--操作语句
update T1 set T1_2='32h4' where ID=@fID
FETCH NEXT FROM tmpGoods into @fID
END
CLOSE tmpGoods
DEALLOCATE tmpGoods
END
END