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 2005 Forums
 Transact-SQL (2005)
 Triggers!!!

Author  Topic 

ruchirj07
Starting Member

37 Posts

Posted - 2007-10-22 : 07:26:04
Can any1 let me know if deleted table hold the value deleted from table or not.
Scenario is: I need to maintain the history of the table. Update on any record take place by deleting it first and then inserting whole new row. So i have written trigger to track it but it seems after the row is deleted, the data from deleted table is also lost :(

Can any1 tell me the solution for the same.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-10-22 : 07:30:11
Yes. Update is a delete followed by the insert. So Deleted table contains old copy of the data while Inserted table contains new data, for UPDATE action. Show us your code, seems like something wrong with the code.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-10-22 : 08:13:58
If your updates are actually done by a delete followed by an insert then an update trigger will never be fired.
A delete trigger will have the old values in the deleted table and an empty inserted table
An insert trigger will have the new values in the inserted table and an empty deleted table

An insert + delete trigger will be fired twice - once for the insert, once for the delete with tables populated as above.

==========================================
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

ruchirj07
Starting Member

37 Posts

Posted - 2007-10-22 : 08:26:19
My code deletes the record and then insert new record for updating the record and the trigger i'm using id "after insert".

I hope this clears the doubt.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-22 : 08:41:57
Then nr's answer would clear your doubts.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-10-22 : 09:09:57
An insert trigger will have the new values in the inserted table and an empty deleted table

==========================================
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
   

- Advertisement -