Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 How to Catch event in trigger

Author  Topic 

indra_saha
Starting Member

2 Posts

Posted - 2008-09-25 : 16:51:31
Hi,
I am writing a single trigger in T-SQL (in SQL Server 2000) for Insert, Update, Delete on a table.
Inside the body of that trigger I want to perform operation based on what event (insert or update or delete) has occurred.
How will I know and catch the event inside the trigger body.

Any code example will be highly appreciated.

Thanks in advance,
Rabi

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-09-25 : 16:52:56
You'll need to pull the rows from the inserted and/or deleted trigger tables. See SQL Server Books Online for information on these.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-09-25 : 17:09:56
It is probably simpler and more efficient to do a differnt trigger for each one.

You can tell by doing a count of the inserted and deleted tables. If both have rows, it is an update.

CODO ERGO SUM
Go to Top of Page

indra_saha
Starting Member

2 Posts

Posted - 2008-09-25 : 17:36:06
Yes checking for rows in 'inserted' and/or 'deleted' trigger tables would be one option or work around.
Just wondering if there is any T-SQL command or so (like the PL/SQL has it) to do it.

quote:
Originally posted by tkizer

You'll need to pull the rows from the inserted and/or deleted trigger tables. See SQL Server Books Online for information on these.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog


Go to Top of Page
   

- Advertisement -