Categories
Bookmarked MS SQL Server SQL

SQL Update if Record Exists or Insert

Quite often we need an approach where we need to Insert record if it is not already present. Sometime to manage relationship. There are few different way of doing it, like “If Exists”, or “Insert on Duplicate Key” (mysql) but the best I found is one from MSDN Blog Entry ( http://blogs.msdn.com/b/miah/archive/2008/02/17/sql-if-exists-update-else-insert.aspx)

The approach is to simply try update the record, if record present it got updated, if not then it insert new based on “Row Effected variable”.