-- Make a DB to demo in Create database EduTest GO Use EduTest GO -- Create a table - this is the application's table Create Table Table1 ( ID int, col1 varchar(10), col2 varchar(10) ); -- Create a table - this is the imported data Create Table Table2 ( ID int, col1 varchar(10), col2 varchar(10) ); -- insert data into the 'reaal' table. insert into Table1 (ID, col1, col2) values (1, 'some data', 'some data'); insert into Table1 (ID, col1, col2) values (2, 'some data', 'some data'); insert into Table1 (ID, col1, col2) values (3, 'some data', 'some data'); insert into Table1 (ID, col1, col2) values (4, 'some data', 'some data'); -- insert data into the 'import' table. insert into Table2 (ID, col1, col2) values (1, 'some data', 'some data'); insert into Table2 (ID, col1, col2) values (2, 'some data', 'some data'); insert into Table2 (ID, col1, col2) values (3, 'some data', 'new data'); insert into Table2 (ID, col1, col2) values (4, 'some data', 'new data'); insert into Table2 (ID, col1, col2) values (5, 'more data', 'more data'); insert into Table2 (ID, col1, col2) values (6, 'more data', 'more data'); GO -- Have a look at table1 - 4 rows, each field containing 'some data' select * from Table1; -- Have a look at table1 - 6 rows. Note that: -- - the first two are the same as the real data -- - the second two are in the main table, but have different values -- - the final two are new select * from Table2; -- Here's the SQL that does the work -- update existing rows update Table1 set Table1.col1 = Table2.col1, Table1.col2 = Table2.col2 from Table1 inner join Table2 on Table1.ID = Table2.ID; -- insert the new rows INSERT INTO Table1 (ID, col1, col2) select Table2.ID, Table2.col1, table2.col2 FROM Table2 Where Table2.ID not in (select Table1.ID from Table1); -- now check table1 and see what happened: select * from Table1; -- Deleting from the main table isn't necessarily something you'd want to do, -- depends on how your app deals with integrity - you could do so with -- Delete from table1 where table1.ID not in (select table2.ID from table2);