sql server - Copy missing rows from one table to another with multi-column primary key -
this topic related copy missing rows 1 table in sql server stored procedure time problem bit more complex.
i have tables in different databases (on same server) identical. need transfer data rows left database table right database table, want transfer rows aren't in right database table already.
my table have 4 primary keys, see image

i'd use this
insert [extern_epi6r2].[dbo].[tblbigtablereference] select * [extern].[dbo].[tblbigtablereference] ( pkid not in (select pkid [extern_epi6r2].[dbo].[tblbigtablereference]) , propertyname not in (select propertyname [extern_epi6r2].[dbo].[tblbigtablereference]) , iskey not in (select iskey [extern_epi6r2].[dbo].[tblbigtablereference]) , [index] not in (select [index] [extern_epi6r2].[dbo].[tblbigtablereference]) ) but, wont work since stacking of conditions wrong in way.
im using sql server 2008 r2
your query not correct because various conditions can matched on different rows.
insert [extern_epi6r2].[dbo].[tblbigtablereference] select * [extern].[dbo].[tblbigtablereference] s not exists ( select 1 [extern_epi6r2].[dbo].[tblbigtablereference] d d.pkid = s.pkid , d.propertyname = s.propertyname , d.iskey = s.iskey , d.[index] = s.[index] -- terrible column name ); but begs question - why 4 of these columns part of key? pkid not enough? if isn't, sure has strange , incorrect name.
Comments
Post a Comment