|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Hi,
I need to write a trigger for insert, update and delete. But how do I differentiate the action in the trigger.. I need something like this.. if inserted begin insert into user_hist from inserted....... end if updated begin insert into user_hist from updated.... end if deleted begin insert into user_hist from deleted.... end |
|
#2
|
|||
|
|||
|
I don't think it is possible to have different logic for each type in the one trigger. You can however have more than one trigger on a table each of which can be ( but does not have to be) for a different transaction type.
Loads of info in sql help. |
|
#3
|
|||
|
|||
|
Quote:
You can differentiate the actions like this IF SELECT COUNT(*) FROM INSERTED >0 AND SELECT COUNT(*) FROM DELETED >0 THEN --Your update logic here as during update action both inserted and deleted tables get populated with your new values and old values respectively ELSE IF SELECT COUNT(*) FROM INSERTED >0 AND SELECT COUNT(*) FROM DELETED =0 --Your Insert logic here as during insert action only INSERTED table will get populated with values you're inserting ELSE IF IF SELECT COUNT(*) FROM DELETED >0 AND SELECT COUNT(*) FROM INSERTED =0 --Your DELETE logic as during delete action DELETED table alone gets populated |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > SQL Server 2000 - Triggers |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|
|