开发者

Insert statement with where clause

I had a table with unique Date_t1 date type field, but in Table description field is not mentioned as unique, now whil开发者_运维百科e 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,


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜