Calculating Date, Time in SQL-mysql
May 16, 2023
If the key-DUPLICATION-Error occurs during Insert in Mysql, try Update again before Insert, and if it exists, there is also a code that inserts if it does not exist.
There is a way to solve this with SQL at once.
INSERT INTO sample (mykey, name, price, cnt, regtime) VALUES (5, 'young', 100, 55, now())ON DUPLICATE KEY UPDATEprice = price,cnt = cnt + 1,regtime = now()
You can write an Insert statement first, and then write an SQL statement to update in the event of a KEY-DUPLICATION after the ONDUPLICATE KEYUPDATE statement.