dongshuo6503 2010-11-13 11:30
浏览 29
已采纳

这个sql代码会正确更新吗?

I want to update only one field in a mysql table.

I have an "ad_id" which is unique.

The field "mod_date" is a TIMESTAMPS field, which is the one I need to update.

UPDATE main_table
SET main_table.mod_date = NOW()
WHERE classified.ad_id = $ad_id";

I haven't tested this yet because I am afraid it might update all rows.

So I have two questions:

Is there anyway to prevent MySql to update more than 1 row?

Is this sql code correct for updating one row only?

Thanks

  • 写回答

3条回答 默认 最新

  • dtz30833 2010-11-13 11:35
    关注

    If ad_id is unique, it will only update one row (if $ad_id is valid, zero otherwise).

    If your worried about an update like this, rewrite it as a select to confirm which rows it will operate on before running it.

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

报告相同问题?