giovedì, febbraio 27, 2014

How to move records between tables

AD FUTURAM REI MEMORIAM  :)
How to move all records from a source table to a destination table.

This following command only works if the two table are identical (same fields in the same order):

DELETE   [SourceTable]
OUTPUT
            DELETED.*
INTO [DestinationTable]


If stuctures are different, then you need to specify every field you want to copy, respecting the order of the fields of the destination table:

DELETE   [SourceTable]
OUTPUT
              DELETED.Name,
              DELETED.Age,
              DELETED.Address
       INTO [DestinationTable]