douqun1977 2011-10-16 06: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-16 06:32
    关注

    Yes, with REPLACE INTO statements.

    A nice summary and caveats are described here

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

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试