I had a table with unique Date_t1 date type field, but in Table description field is not mentioned as unique, now while inserting new row I need to validate if date exist or not, If already exist I should not allow to make changes on that row, neither a new row needs to be created, Any idea how to resolve this problem in efficient way,
Asked
Active
Viewed 376 times
1 Answers
1
Since you're using a UNIQUE index.. you can use this to your advantage with INSERT IGNORE
Consider the following:
INSERT IGNORE INTO your_table SET id = 100 ...
Assuming id
is the UNIQUE
column here... MySQL will throw an error if you try to re-insert this. But since you're using IGNORE
, the error is silently thrown away.

Matt
- 43,482
- 6
- 101
- 102