

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to revert rows to default column value in MySQL?
To revert rows to default column value, let us first create a demo table
mysql> create table defaultDemo -> ( -> Id int -> ); Query OK, 0 rows affected (0.48 sec)
Insert some records in the table using insert command.
The query is as follows
mysql> insert into defaultDemo values(10); Query OK, 1 row affected (0.25 sec) mysql> insert into defaultDemo values(20); Query OK, 1 row affected (0.13 sec) mysql> insert into defaultDemo values(30); Query OK, 1 row affected (0.14 sec) mysql> insert into defaultDemo values(40); Query OK, 1 row affected (0.11 sec) mysql> insert into defaultDemo values(80); Query OK, 1 row affected (0.18 sec) mysql> insert into defaultDemo values(90); Query OK, 1 row affected (0.14 sec) mysql> insert into defaultDemo values(100); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement.
The query is as follows
mysql> select *from defaultDemo;
The following is the output
+------+ | Id | +------+ | 10 | | 20 | | 30 | | 40 | | 80 | | 90 | | 100 | +------+ 7 rows in set (0.00 sec)
Here is the query to revert rows to default column value in MySQL
mysql> update defaultDemo set Id=default where Id > 45; Query OK, 3 rows affected (0.39 sec) Rows matched: 3 Changed: 3 Warnings: 0
Check the table records once again.
The query is as follows
mysql> select *from defaultDemo;
The following is the output
+------+ | Id | +------+ | 10 | | 20 | | 30 | | 40 | | NULL | | NULL | | NULL | +------+ 7 rows in set (0.00 sec)
- Related Questions & Answers
- How to modify column default value in MySQL?
- Set default value to a JSON type column in MySQL?
- How to check whether column value is NULL or having DEFAULT value in MySQL?
- How to create boolean column in MySQL with false as default value?
- How to set MySQL default value NONE?
- How to set default value to NULL in MySQL?
- How to set default Field Value in MySQL?
- Reset MySQL field to default value?
- Group MySQL rows in an array by column value?
- How do I set the default value for a column in MySQL?
- Change tinyint default value to 1 in MySQL?
- How to use a function for default value in MySQL?
- How to set default value for empty row in MySQL?
- Exclude rows based on column value when another duplicate column value is found in MySQL?
- MySQL query to select rows where column value is only 0, group by another column?
Advertisements