Update records in Table1 from Table2 if records exist or Insert new records from TAble1 into Table2 - SQL Server 2005
Posted on 2008-10-09
What is the correct syntax to Update existing records or insert new records into one table from another table?
For Example:I have two tables that are identical (Same exact columns, column definitions and primary keys) - Call them Table1 and Table2. I want to fill Table2 with records from Table1 periodically. Table2 will hold all of the records and Table1 acts as a temporary table that only has the lates records .
I want to update the existing records in Table2 with the same "changed" records in table1. Also I would like to insert any new records (not already in Table2) into Table2 from Table1.
If records exist in Table2
Update these records in Table2 from Table1
if records do not exist in Table2
Insert new records from Table1 into Table2
What is the correct syntax to do this?