Search code snippets, questions, articles...

Create or update records Mysql/Sql

INSERT INTO UserDetail(UserId, About) 
VALUES (1,'This is about insert text') 
ON DUPLICATE KEY UPDATE About = 'This is about update text';
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

'UserId' must be the primary key or Unique key to make this query work. When you hit this first time it will insert records into UserDetail table. Here we have made UserId Unique key. When you again execute the above SQL query again it will update the records which have UserId 1.

Search Index Data (The code snippet can also be found with below search text)

mysql insert record if not exists
Was this helpful?
0 Comments