sql upsert 1

sql upsert

update table1 
set name = 'val2', itemname = 'val3', itemcatName = 'val4', itemQty = 'val5'
where id = 'val1'
if @@ROWCOUNT = 0
insert into table1(id, name, itemname, itemcatName, itemQty)
values('val1', 'val2', 'val3', 'val4', 'val5')

Here is what the above code is Doing:
1. It is updating the table1 with the values provided in the query.
2. If the update is not successful, it will insert the values into the table.
3. If the update is successful, it will not insert the values into the table.

Similar Posts