Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Select differences with composite key

Author  Topic 

beatkeeper25
Starting Member

27 Posts

Posted - 2015-01-23 : 10:36:18
I backed up a table (select * into table_bak from tableA).
Then ran a script to delete certain records from tableA. I want to rollback that delete, basically insert records from table_bak that don't exist in tableA. It has a composite primary key with 3 columns. I'm assuming it would be a join between the 2 tables on the 3 keys, but can't figure it out.

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-01-23 : 10:40:55
insert into tablea a
select
from table_bak b
where not exists(
select 1 from tablea a
where a.col1 = b.col1
and a.col2 = b.col2
and a.col3 = b.col3
)
Go to Top of Page

beatkeeper25
Starting Member

27 Posts

Posted - 2015-01-23 : 11:21:18
Thanks!
Go to Top of Page
   

- Advertisement -