我正在使用sql-server 2012,并且编写了这样的触发器:
ALTER TRIGGER [dbo].[ModValue]
ON [dbo].[Table1]
AFTER UPDATE
AS
BEGIN
SET NOCOUNT ON;
declare @ocid bigint
declare @ncid bigint,@pid bigint
set @ocid=(select CategoryId from deleted)
select @ncid=CategoryId,@pid=Id from inserted
if(@ocid<>@ncid)
begin
delete from [Table2] where ProductId=@pid
delete from [Table3] where ProductId=@pid
delete from [Table4] where ProductId=@pid
end
END
当我想更新我的表(Table1)时,出现此错误:
消息512,级别16,状态1,过程ModValue,行15
子查询返回的值超过1。当子查询遵循=,!=,<,<=,>,> =或将子查询用作表达式时,不允许这样做。该语句已终止。
更新查询:
update Table1
set sizing = 0
where categoryid = 238
该脚本有什么问题?
我认为以下是问题所在:
set @ocid=(select CategoryId from deleted)
SET
命令期望SELECT
语句中最多1行。deleted
表格可能包含多于1行,因为触发器将在batch
级别而非record
级别上触发。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句