Olá.
Estou querendo sincronizar uma tabela com o Linked Server, porém o problema é que a tabela tem chave primária composta, e não sei como fazer a verificação para buscar o registro. Alguém pode me ajudar por favor?!
Obrigada!
Stack Overflow em Português é um site de perguntas e respostas para programadores profissionais e entusiastas. Leva apenas um minuto para se inscrever.
Inscreva-se para participar desta comunidadeDesta forma que vou lhe mostrar garante a integridade dos dados com o uso do transaction, veja se isso lhe ajuda:
begin tran
if exists (select * from Sua_tabela with (updlock,serializable) where key1 = @key1 and key2 = @key2)
begin
update Sua_tabela set ...
where key1 = @key1 and key2 = @key2
end
else
begin
insert Sua_tabela (key1, key2 ...)
values (@key1, @key2, ...)
end
commit tran
ou
begin tran
update Sua_tabela with (serializable) set ...
where key = @key and key2 = @key2
if @@rowcount = 0
begin
insert Sua_tabela (key1, key2, ...) values (@key1, @key2, ...)
end
commit tran