Wednesday, April 7, 2010

Using SELECT to INSERT records

If your tables are EXACTLY the same and they do not have any constraints that would prevent a direct insert, then you may use:

INSERT INTO tabelename (the table you want to copy into)
SELECT * from tablename (the table you want to copy from)
WHERE Field10 = (some condition)

This is a clean and easy way to copy data.


The same concept using a simple query without a condition

INSERT INTO table1
SELECT * from table2


No comments:

Post a Comment