UPDATE if exists else INSERT in SQL

后端 未结 4 1879
离开以前
离开以前 2020-12-07 01:51

I\'m trying to implement a SQL query to \"UPDATE if exists else INSERT\"

My table(Allowance) is as below:

EmployeeID int(8) PK
Year year         


        
4条回答
  •  臣服心动
    2020-12-07 02:23

    The below query will fulfill your requirement.

    INSERT INTO `ALLOWANCE` (`EmployeeID`, `Year`, `Month`, `OverTime`,`Medical`,
    `Lunch`, `Bonus`, `Allowance`) values (10000001, 2014, 4, 10.00, 10.00,
    10.45, 10.10, 40.55) ON DUPLICATE KEY UPDATE `EmployeeID` = 10000001
    

提交回复
热议问题