开发者

How to Check for record existence and do Insert in MYSQL?

How to Check for record existence and do Insert or Update in MYSQL ?

I have a script, which has set of Insert statements for multiple tables. Now when i try to execute the Insert statement, i want to do the following:

  • Check for t开发者_运维百科he record existence and then do Insert or Update.
  • If the Record is not exist do Insert.
  • If the Record is already do not do anything.

How to accomplish this ?

Note : The script with Insert Statements are generated programmaticaly using SP


Use INSERT IGNORE :

INSERT IGNORE INTO table_name
SET column = value
   ...


This is what mysqls replace is for

http://dev.mysql.com/doc/refman/5.0/en/replace.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜