Replace (Update/Insert) a row into SQL Server table


In Mysql,  we use “replace into” to either updates or inserts a row in a table.

How to do it in SQL Server?

Just like this:

if not exists (select 1 from employees where employee_id = 1)
      insert into employees (employee_id,last_name,first_name) values ( 1,'smith', 'bob' )
      update employees set last_name='smith' , first_name='bob' where employee_id = 1

And in Oracle,

In DB2,

In PostgreSQL,

In Sqlite,

Some SQL Server tools you can try: