This topic is related to Copy missing rows from one table to another in sql server with stored procedure but this time the problem is a bit more complex.
I have to tables in different databases (on the same server) that are identical. I need to transfer the data rows from the left database table to the right database table, but I only want to transfer the rows that aren’t in the right database table already.
My table have four primary keys, see image

I’d like to use something like this
insert into [EXTERN_EPI6R2].[dbo].[tblBigTableReference]
select * from [EXTERN].[dbo].[tblBigTableReference]
where (
pkId not in (select pkId
from [EXTERN_EPI6R2].[dbo].[tblBigTableReference])
and PropertyName not in (select PropertyName
from [EXTERN_EPI6R2].[dbo].[tblBigTableReference])
and IsKey not in (select IsKey
from [EXTERN_EPI6R2].[dbo].[tblBigTableReference])
and [Index] not in (select [Index]
from [EXTERN_EPI6R2].[dbo].[tblBigTableReference])
)
But, that wont work since the stacking of the conditions is wrong in some way.
Im using SQL Server 2008 R2
Your query is not correct because your various conditions can be matched on different rows.
But this begs the question – why are all four of these columns part of the key? Is
pkIdnot enough? If it isn’t, it sure has a strange and incorrect name.