Even better, you can put records in a temporary table, then update everything existing and insert everything that doesn't exist with two queries.
Example:
select Column1 = 1, Column2 = 2, Column3 = 3
into
union all select 1,2,3
union all select 1,2,3
union all select 1,2,3
...
union all select 1,2,3
update t
set Column1 = p.Column1, Column2 = p.Column2, Column3 = p.Column3
from table t
inner join
insert into table (Column1, Column2, Column3)
select p.Column1, p.Column2, p.Column3
from
left join table t on t.Column1 = p.Column1
where t.Column1 is null
drop table
Guffa source
share