<t>don't forget about transactions. Performance is good, but simple (IF EXISTS..) approach is very dangerous.<br/>
<br/>
When multiple threads will try to perform Insert-or-update you can easily <br/>
get primary key violation.<br/>
<br/>
Solutions provided by @Beau Crawford & @Esteban show general idea but error-prone.<br/>
<br/>
To avoid deadlocks and PK violations you can use something like this: <br/>
<br/>
begin tran<br/>
if exists (select * from table with (updlock,serializable) where key = @key)<br/>
begin<br/>
update table set ...<br/>
where key = @key<br/>
end<br/>
else<br/>
begin<br/>
insert into table (key, ...)<br/>
values (@key, ...)<br/>
end<br/>
commit tran<br/>
<br/>
```<br/>
<br/>
or<br/>
<br/>
```<br/>
begin tran<br/>
update table with (serializable) set ...<br/>
where key = @key<br/>
<br/>
if @@rowcount = 0<br/>
begin<br/>
insert into table (key, ...) values (@key,..)<br/>
end<br/>
commit tran<br/>
<br/>
```</t>