

- 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 can I insert default value in MySQL ENUM data type?
We can do it with the help of the DEFAULT attribute of the ENUM data type. The DEFAULT attribute causes an ENUM data type to have a default value when a value is not specified. In other words, we can say that INSERT statement does not have to include a value for this field because if it does not include then the value following DEFAULT will be inserted. Functions are not allowed in the DEFAULT expression. For ENUM data type the DEFAULT values include NULL and empty string (‘’).
Example
mysql> Create table enum123(Rollno INT, Name Varchar(20), result ENUM('Pass','Fail') DEFAULT 'Fail'); Query OK, 0 rows affected (0.12 sec) mysql> Insert into enum123(Rollno, Name) Values(25, 'Raman'); Query OK, 1 row affected (0.13 sec)
We have not inserted any value in ‘result’ column hence it will pick the word following DEFAULT as the value. In this case by default value ‘fail’ would be inserted.
mysql> Select * from enum123; +---------+--------+--------+ | Rollno | Name | result | +---------+--------+--------+ | 25 | Raman | Fail | +---------+--------+--------+ 1 row in set (0.00 sec)
- Related Questions & Answers
- What MySQL returns if I insert invalid value into ENUM?
- How can I remove a value from an enum in MySQL?
- What is MySQL ENUM data type? What are the advantages to use ENUM data type?
- Add a new value to a column of data type enum in MySQL?
- How can we specify default values in MySQL INSERT statement?
- How do I insert a NULL value in MySQL?
- Do MySQL Can Enum type values contain spaces in it?
- How can I modify an existing MySQL column’s data type?
- How can I get enum possible values in a MySQL database?
- How do I add more members to my ENUM - type column in MySQL?
- what are the different attributes of MySQL ENUM data type?
- Set default value to a JSON type column in MySQL?
- MySQL ORDER BY 'ENUM' type value based on conditions
- How can we insert data into a MySQL table?
- What is the default type of a hexadecimal value in MySQL?
Advertisements