March 11, 2010 at 10:46 am
Hi,
It is possible to do something like this in SQL Server Triggers?
If INSERT, do this;
If UPDATE, do that;
It is possible?
Best Regards,
March 11, 2010 at 11:04 am
Create one trigger FOR INSERT and put the insert logic in that, create a second trigger FOR UPDATE and put the update logic in there.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 11, 2010 at 11:07 am
Yes, basically you will have rows in inserted and deleted pseudotables for UPDATE, in inserted for INSERT and in deleted only for DELETE.
So you'd have to check something like
if(exists (select 1 from inserted) and not exists(select 1 from deleted)) -- this is INSERT
if(exists (select 1 from inserted) and exists(select 1 from deleted)) -- this is UPDATE
...
Regards
Piotr
...and your only reply is slàinte mhath
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply