- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Set all values in a MySQL field to 0?
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)
- Related Articles
- MySQL query to set current date in the datetime field for all the column values
- How to get the possible values for SET field in MySQL?
- How to set all values in a single column MySQL Query?
- In MySQL how to replace all NULL values in a particular field of a particular table?
- Set conditions for columns with values 0 or 1 in MySQL
- Concatenate a string in an already created field values set with MySQL TEXT data type
- List all values of a certain field in MongoDB?
- How to count all characters in all rows of a field in MySQL?
- How to set default Field Value in MySQL?
- Set the NULL values to 0 and display the entire column in a new column with MySQL SELECT
- SET only two values for all the rows in a MySQL table based on conditions?
- Find all the non-distinct values of a field in MongoDB?
- Set numbers as a varchar field and compare in MySQL
- Pushing values into array with multi field set to TRUE?
- How to update a column with the same values (not all) using UPDATE, SET and LIMIT in MySQL?

Advertisements