| Start |
|---|
| Copy data from one table to another This code selects data out of a table and displays it in the query tool (usually SSMS) This code inserts that data into a table: |
| Copy data into a table, creating that table on the fly This code selects data out of a table: This code creates a new table called |
| Move data into a table (assuming unique keys method) To move data you first insert it into the target, then delete whatever you inserted from the source table. This is not a normal SQL operation but it may be enlightening What did you insert? Normally in databases you need to have one or more columns that you can use to uniquely identify rows so we will assume that and make use of it. This statement selects some rows First we insert these into our target table: Now assuming records in both tables are unique on This will only work correctly if Lastly, we don't want the job half done. If we wrap this up in a transaction then either all data will be moved, or nothing will happen. This ensures we don't insert the data in then find ourselves unable to delete the data out of the source. |
Read Article
https://develop.horje.com/learn/1434/reference