I have a trigger but when it tries to run I get
The Row values(s) updated or deleted either do not make the row unique…
I want to update a table when the col REDEEMED in the triggered table is updated.
What do I need to change in my trigger to make this work?
Table GeneratedCouponCounter:
Id int (primary key)
CouponId int
NrOfRedeemedCoupons int
NrOfGeneratedCoupons int
LastGenerated datetime
LastRedeemed datetime
CreatedOn datetime
Trigger:
CREATE TRIGGER trigger_update
ON GeneratedCoupon2
AFTER UPDATE
AS
IF( UPDATE(REDEEMED))
begin
update GeneratedCouponCounter
SET NrOfRedeemedCoupons = NrOfRedeemedCoupons +1,[LastRedeemedOn] = getdate()
where CouponId IN (SELECT CouponID from INSERTED)
end
Thanx!
/Mike
Create
PRIMARY KEYonGeneratedCoupon2table, also theWHEREpart of update will case errors when you update more than one record on ‘GeneratedCoupon2’ table. Change it to:where CouponId IN (SELECT CouponID from INSERTED)EDIT:
Changed table name where KEY is needed to reflect fix to the problem.