首页 > 解决方案 > 如何编写更新查询以清除数据库中的选定数据?

问题描述

我有一个数据库,在抱怨表中有列 assign_date 和 tec_id。我通过更新查询将数据添加到 assign_date 和 tec_id 字段。我想要做的是明确两列使用更新查询。我不能删除数据。所以我不能使用删除查询。我怎么做?

assign_date 具有 DateTime 数据类型,而 tec_id 具有 int 数据类型。

我尝试的是,

    $id=0;
    $date=date("0000-00-00 00:00:00");
 
    $sql = 'UPDATE complains SET tec_id="NULL", assign_date="NULL" WHERE refno=?';

图片

谢谢你。

标签: mysql

解决方案


update complains set assign_date=null, tech_id=null where id=:id 当然,这些字段应该允许空值。


推荐阅读