触发器失效
问题是更新触发无效
具体解释:
当我使用 update 表 set xx= 'value ' where id=1时触发器没问题,然而当我用where id like ....时 数据更新了,但触发器只更新了第一项
难道模糊查询对触发器无效?
请教个位高手了,模糊查询一定要用的,怎么解决这个问题啊?
------解决方案--------------------CREATE TRIGGER Tr_updateNewPrice
ON dbo.ProductColor
FOR UPDATE
AS
begin
if update(NewPrice)
update p
set
newPrice=i.newPrice
from
productColor p,
inserted i
where
p.ArticleCode=i.artcileCode
and
p.ColourCode =i.colourCode
end
go
------解决方案--------------------CREATE TRIGGER Tr_updateNewPrice
ON dbo.ProductColor
FOR UPDATE
AS
if update(NewPrice)
begin
declare @artcileCode varchar(50)
declare @colourCode varchar(50)
declare @newPrice money
declare tempcur cursor for
select
ArticleCode,
ColourCode,
newPrice
from inserted
open tempcur
fetch next from tempcur into @artcileCode,@colourCode,@newPrice
while @@fetch_status=0
begin
update productColor set newPrice=@newPrice
where ArticleCode=@artcileCode and ColourCode=@colourCode
fetch next from tempcur into @artcileCode,@colourCode,@newPrice
end
close tempcur
deallocate tempcur
end