Getting Started with Adobe After Effects - Part 6: Motion Blur
A collection of quick technology learning tips from what people around you learn every day

Delete Original Data and maintain history with single SQl statement......

Oct 3 2012 12:00AM by Nirav Gandhi   

Hello friends, one interviewer asked that suppose you have two tables Employee_Details, Employee_Details_History

now I want to delete original table Employee_details and maintain it’s history to other table.

How can it’s possible with only single SQL statement?

delete from Employee_Details
OUTPUT deleted.* into Employee_Details_History
Read More..   [32134 clicks]

Published under: SQL Server Tips · TSQL Tips ·  ·  · 


Nirav Gandhi
38 · 5% · 1503
14
 
4
 
10
 
0
Incorrect
 
0
Interesting
 
0
Forgotten



Submit

3  Comments  

  • Output clause can be used with DML commands (insert, update, delete).

    It works using magic tables of deleted and inserted.

    If you re-write the above query as

       delete from Employee_Details
       OUTPUT deleted.*;
    

    It will return the records affected.

    if you set sp_configure for option "disallow results from triggers", output clause without into will raise the error.

    commented on Oct 4 2012 5:05AM
    kr.roopesh
    818 · 0% · 35
  • Thanks For sharing.....

    commented on Oct 5 2012 10:43PM
    Jagdish Ilasariya
    1939 · 0% · 8
  • @kr.roopesh actually, DELETE can have two OUTPUT clauses - one with INTO and one without. Then in one statement you delete from transaction table, insert into history table, and output to application that will process transactional rows.

    commented on Oct 6 2012 8:06AM
    chojrak11
    1009 · 0% · 25

Your Comment


Sign Up or Login to post a comment.

"Delete Original Data and maintain history with single SQl statement......" rated 5 out of 5 by 14 readers
Delete Original Data and maintain history with single SQl statement...... , 5.0 out of 5 based on 14 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]