create trigger tr_update on 表
for update
as
declare @主键 int
if update(某列) --检查有没有被更新
begin
if exists(select 1 from inserted where 某列=3)
begin
DECLARE tables_cursor CURSOR FOR
select 主码 from inserted where 某列=3
open tables_cursor
FETCH NEXT FROM tables_cursor INTO 变量2
WHILE (@@FETCH_STATUS = 0)
BEGIN
-------执行相关代码
FETCH NEXT FROM tables_cursor INTO 变量2
END
close tables_cursor
deallocate tables_cursor
end
else
begin
----执行相关代码
create trigger tr_update on 表
for update
as
declare @主键 int
if update(某列) --检查有没有被更新
begin
select @主键=主键 from inserted where 某列=3
if @@rowcount>1---如果总数大于1
begin
DECLARE tables_cursor CURSOR FOR select 主码 from inserted where 某列=3
begin
open tables_cursor
FETCH NEXT FROM tables_cursor INTO 变量2
WHILE (@@FETCH_STATUS = 0)
BEGIN
-------执行相关代码
FETCH NEXT FROM tables_cursor INTO 变量2
END
close tables_cursor
end
create trigger tr_update on 表
for update
as
declare @主键 int
if update(某列) --检查有没有被更新
begin
select @主键=主键 from inserted where 某列=3
if @@rowcount=0 --如果=0,则是没有被更新为3
print '没有被更新为3'
else
begin
select 被更新的主键=@主键
end
end