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
 SQL Server Development (2000)
 triggers - to cature before and after changes

Author  Topic 

priyaram
Yak Posting Veteran

82 Posts

Posted - 2005-06-09 : 12:07:02
Hi

I created a trigger to capture the changes in the table.
That trigger will capture the old values and new values for particular column.
Is ther any way that we can cature the entire record as before and after change
for update and delete.

Thanks

mpetanovitch
Yak Posting Veteran

52 Posts

Posted - 2005-06-09 : 12:10:07
You can reference inserted and deleted as tables. These tables hold what was before and after in the table.

Update (has inserted/deleted)
Delete (has deleted)
Insert (has inserted)

From BOL:
Two special tables are used in trigger statements: the deleted table and the inserted table. Microsoft® SQL Server™ 2000 automatically creates and manages these tables. You can use these temporary, memory-resident tables to test the effects of certain data modifications and to set conditions for trigger actions; however, you cannot alter the data in the tables directly

Mike Petanovitch
Go to Top of Page

priyaram
Yak Posting Veteran

82 Posts

Posted - 2005-06-09 : 13:03:28
i am getting what you are saying
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2005-06-11 : 10:15:59
see
http://www.nigelrivett.net/SQLTriggers/Triggers_1_A_beginners_guide.html
http://www.nigelrivett.net/SQLTriggers/Triggers_2_Creating_Audit_Trails.html
http://www.nigelrivett.net/SQLTriggers/GenerateTriggerForAudit.html
http://www.nigelrivett.net/SQLTriggers/AuditTrailTrigger.html

Beware of text columns

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Pakl
Starting Member

10 Posts

Posted - 2005-06-14 : 03:54:03
Great articles... Thanks nr!
Go to Top of Page
   

- Advertisement -