要将字段中的所有值设置为0,请使用update命令-update yourTableName set yourColumnName=0;
让我们首先创建一个表-mysql> create table DemoTable
(
Number int
);
使用插入命令在表中插入一些记录-mysql> insert into DemoTable values(10);
mysql> insert into DemoTable values(4757);
mysql> insert into DemoTable values(48474);
mysql> insert into DemoTable values(35465);
使用select语句显示表中的所有记录-mysql> select *from DemoTable;
输出结果+--------+
| Number |
+--------+
| 10 |
| 4757 |
| 48474 |
| 35465 |
+--------+
4 rows in set (0.00 sec)
以下是将MySQL字段中的所有值设置为0的查询-mysql> update DemoTable set Number=0;
Rows matched: 4 Changed: 4 Warnings: 0
让我们再次检查表记录-mysql> select *from DemoTable;
输出结果+--------+
| Number |
+--------+
| 0 |
| 0 |
| 0 |
| 0 |
+--------+
4 rows in set (0.00 sec)