sql insert update if exists code example
Example 1: sql server if exists update else insert
if exists(SELECT * from Student where FirstName='Akhil' and LastName='Mittal')
BEGIN
update Student set FirstName='Anu' where FirstName='Akhil'
End
else
begin
insert into Student values(1,'Akhil','Mittal',28,'Male',2006,'Noida','Tenth','LFS','Delhi')
end
Example 2: mysql insert exists update
INSERT INTO table (column_list)
VALUES (value_list)
ON DUPLICATE KEY UPDATE
c1 = v1,
c2 = v2,
...;