To set all the values in a field to 0, use the update command −
update yourTableName set yourColumnName=0;
Let us first create a table −
mysql> create table DemoTable ( Number int ); Query OK, 0 rows affected (0.64 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(4757); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(48474); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values(35465); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+--------+ | Number | +--------+ | 10 | | 4757 | | 48474 | | 35465 | +--------+ 4 rows in set (0.00 sec)
Following is the query to set all values in a MySQL field to 0 −
mysql> update DemoTable set Number=0; Query OK, 4 rows affected (0.17 sec) Rows matched: 4 Changed: 4 Warnings: 0
Let us check table records once again −
mysql> select *from DemoTable;
Output
+--------+ | Number | +--------+ | 0 | | 0 | | 0 | | 0 | +--------+ 4 rows in set (0.00 sec)