

- 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
Display only the default values set for columns in MySQL
Let us first create a table and set default values −
mysql> create table DemoTable803(UserId int DEFAULT 101,UserName varchar(100) DEFAULT 'Chris'); Query OK, 0 rows affected (1.18 sec)
Insert some records in the table using insert command. For the values we are not inserting, the default values will get set automatically −
mysql> insert into DemoTable803 values(102,'Chris'); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable803(UserName) values('Mike'); Query OK, 1 row affected (0.48 sec) mysql> insert into DemoTable803(UserId) values(103); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable803 values(); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable803 values(110,'Robert'); Query OK, 1 row affected (0.33 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable803;
This will produce the following output −
+--------+----------+ | UserId | UserName | +--------+----------+ | 102 | Chris | | 101 | Mike | | 103 | Chris | | 101 | Chris | | 110 | Robert | +--------+----------+ 5 rows in set (0.00 sec)
Following is the query to display the default values only −
mysql> select default(UserId),default(UserName) from DemoTable803 limit 1;
This will produce the following output −
+-----------------+-------------------+ | default(UserId) | default(UserName) | +-----------------+-------------------+ | 101 | Chris | +-----------------+-------------------+ 1 row in set (0.00 sec)
- Related Questions & Answers
- Set DEFAULT values for columns while creating a table in MySQL
- Set multiple values for custom columns in MySQL?
- Implement MySQL IN for 2 columns to display only selected records
- Insert row with only default values in MySQL
- Set value only for NULL values in a MySQL table
- Only display specified values inside the IN clause with MySQL?
- Set conditions for columns with values 0 or 1 in MySQL
- Set the default character set in MySQL
- Count only null values in two different columns and display in one MySQL select statement?
- SET only two values for all the rows in a MySQL table based on conditions?
- Display 1 for NULL values in MySQL
- MySQL query to display only the empty and NULL values together?
- MySQL query to compare and display only the rows with NULL values
- Set ENUM in MySQL for column values
- How do I set the default value for a column in MySQL?
Advertisements