douqun1977 2011-10-15 22:23
浏览 163
已采纳

如果该行的主键在插入时已经存在,Mysql会自动替换行吗?

I am building a web-scrapper which pulls data from websites and store it in database table . Primary key of the table is {timestamp+websitename} . Where timestap taken from that website . This happen in every 30 mins .

There are two possiblities a) I pulled the same data gain b) The content got edited on that website but still primary key remain same since creation time (timestap of this post) and website name remain unchanged.

Now I don't want to check using PHP weather same primary key exist or not. I just want data to get pushed into the database without giving me integrity constrain error . I want to do it for efficiency . Is there a way to do it in Mysql ? .

In simple words if row with same primary key already exist simply replace it with the current without throwing integrity constrain at me .

  • 写回答

2条回答 默认 最新

  • douyan1944 2011-10-15 22:32
    关注

    Yes, with REPLACE INTO statements.

    A nice summary and caveats are described here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部