mysql - 如何编写更新查询以清除数据库中的选定数据?
问题描述
我有一个数据库,在抱怨表中有列 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=?';
谢谢你。
解决方案
update complains set assign_date=null, tech_id=null where id=:id
当然,这些字段应该允许空值。
推荐阅读
- firebase - Firebase 推送通知在试飞中不起作用
- c# - 将 xaml.cs 后面的代码移动到 xamarin 中的 ViewModel
- ios - 如何结合 NSLineBreakByCharWrapping 和 NSLineBreakByTruncatingTail?
- javascript - 组件的单个实例反应原生
- python - 在 Python 中将列表转换为整数
- java - 如何使用 Java 在 AWS lambda 函数中创建 S3 存储桶
- c# - 在远程服务器上部署站点后获取 System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf?
- webpack - Vue CLI - 在静态文件中包含资产文件夹中的图像
- c# - 返回相同对象的类中的通用方法
- javascript - crockjs 和 apply 函数需要一个函数作为值