
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- How to modify column default value in MySQL?
- How to create boolean column in MySQL with false as default value?
- How to check whether column value is NULL or having DEFAULT value in MySQL?
- Set default value to a JSON type column in MySQL?
- How to set default value to NULL in MySQL?
- How to set default Field Value in MySQL?
- How to set MySQL default value NONE?
- How do I set the default value for a column in MySQL?
- Group MySQL rows in an array by column value?
- Reset MySQL field to default value?
- How to use a function for default value in MySQL?
- How to set default value for empty row in MySQL?
- MySQL query to select rows where column value is only 0, group by another column?
- Exclude rows based on column value when another duplicate column value is found in MySQL?
- Change tinyint default value to 1 in MySQL?

Advertisements