Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to insert the data deleted out of the entire database in a single table?
I read that you can do with a trigger but I have not an example, someone who can help me please
Posted
Comments
karthik Udhayakumar 25-Jan-14 10:41am    
Hello ,
Can you explain more
This is only possible when you have columns of all the tables same in DB,which practically doesn't work

Otherwise you need a secondary repository for each table(i.e Duplicate table for each)

you can some logic like this to pull the deleted from one to another
<pre lang="SQL">DELETE FROM MyTable OUTPUT DELETED.* INTO MyOtherTable</pre>
or use trigger like this to transfer data
<pre lang="SQL">
CREATE TRIGGER [dbo].[myTrigger] ON [dbo].[myTable] FOR DELETE AS INSERT INTO [dbo].[myOtherTable] ([col1], [col2], [col3]) SELECT [col1], [col2], [col3] FROM [deleted] </pre>

All the best:)

1 solution

In SQL the triggers you can create on database level are about DDL (Data Definition Language).
So if you wan't to handle deletions from different tables you must add trigger to all of them.
About the writing - you will have the problem of different columns in different tables. One way to solve is using XML on the target table...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900