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.
| Author |
Topic |
|
pnpsql
Posting Yak Master
246 Posts |
Posted - 2011-12-19 : 08:13:27
|
| hi team, i need to write a proc that delete a row from table and insert same row into another table without affecting current rows of that table.challenge everything |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-12-19 : 08:16:10
|
If you are on SQL 2005 or higher, the simplest probably is to use the OUTPUT clause. It would be something like this:DELETE YourOldTableOUTPUT DELETED.Col1, DELETED.Col2 --,etc. INTO YourNewTableWHERE -- appropriate where clausehere. http://msdn.microsoft.com/en-us/library/ms177564.aspx |
 |
|
|
pnpsql
Posting Yak Master
246 Posts |
Posted - 2011-12-19 : 23:10:33
|
| is there any other waychallenge everything |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-20 : 00:07:32
|
quote: Originally posted by pnpsql is there any other waychallenge everything
other way is to use trigger. create a trigger on YourOldTable for DELETE and do insertin inside thatsomething likeCREATE TRIGGER TriggernamehereON YourOldTableFOR DELETEASBEGIN INSERT INTO YourNewTable (Col1,Col2,..)SELECT Col1,Col2,..FROM DELETEDEND ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|