[英]How to change the value of this field in all the records of this MySql table?
I have the following situation. 我有以下情况。
In a MySql database I have a posts table. 在MySql数据库中,我有一个posts表。 This table contains the following 2 fields: post_modified and post_date
该表包含以下2个字段: post_modified和post_date
For each record present in the posts table I need set the value of post_modified field with the value into the post_date 对于帖子表中存在的每条记录,我需要将post_modified字段的值设置为post_date
How can I do a query that do this work on all the table records? 我该如何查询所有表记录呢?
Tnx 特纳克斯
这很简单:
UPDATE posts SET post_modified = post_date;
此查询应完成以下工作:
UPDATE posts SET post_modified=post_date;
You would just use an update
without a condition to update all records: 您将使用无条件的
update
来更新所有记录:
update posts set post_modified = post_date
Depending on the settings in the database an update without a condition might not be allowed. 根据数据库中的设置,可能不允许无条件的更新。 Then you would add a dummy condition just to tell the database that you actually want to change every record:
然后,您将添加一个虚拟条件,以告知数据库您实际上要更改每条记录:
update posts set post_modified = post_date where 1 = 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.