triggers - Update rows only the first time in SQL Server -
with trigger show below update price
of products rebates. want in later insertions, records discount has been applied must not updated.
what can add?
create trigger tri on t1 after insert update t1 set cost = case when column1 = 'rebate' cost * 0.5 else cost end
right now, triggers updates all rows in table every time insert anything.
what need include values inserted
pseudo table - table lists rows actually inserted - update just those (and leave else untouched).
so seek alter trigger this:
create trigger tri on dbo.t1 after insert update t1 set cost = case when column1 = 'rebate' cost * 0.5 else cost end inserted -- pseudo table inserted rows i.id = t1.id -- create status match rows up, based on "id" column
sql-server triggers sql-update
No comments:
Post a Comment