delete
as
if @@rowcount=0
return
if @@rowcount>1
begin
rollback transaction
raiserror('you can only delete one information at one time',16,1)
end
return
raiserror 拼写是对的,我删除三条记录,他也能成功
什么时候会弹出raiserror('you can only delete one information at one time',16,1)的提示信息,if @@rowcount=0
return不理解,
if @@rowcount>1
begin
rollback transaction
raiserror('you can only delete one information at one time',16,1)
end
是说删除的行数大于一行的话就执行begin----end 中的语句麻?还是另有意思?
删除的数多于一条的话就不能让它删除.删除数多于一条就会有警告,这个触发器就是控制只能删除一条的
if @@rowcount=0
return
没有记录被删除就退出触发器.避免它在触发器中逗留的时间过长
我一次删除三条它都不告警呀!
drop trigger deltrigger
go
create trigger deltrigger on tb after
delete
as
if @@rowcount=0
return
if ( select count(*) from deleted )>1
begin
rollback transaction
raiserror('you can only delete one information at one time',16,1)
end
改成这个吧,不知道你那个为什么不行
create trigger deltrigger on tb after
delete
as
declare @count int
set @count=@@rowcount
if @@rowcount=0
return
if @count>1
begin
rollback transaction
raiserror('you can only delete one information at one time',16,1)
end
这样也行.可能是@@rowcount的使用有限制吧,具体的我也不清楚