![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Enum with NOT NULL in a MySQL field?
In ENUM data type, if you do not declare NOT NULL then it gives the default value NULL. However, if you declare NOT NULL then it gives the first value from the ENUM.
CASE 1 −When the ENUM gives NULL value. Let us first create a table:
mysql> create table DemoTable1(isMarried ENUM('YES','NO')); Query OK, 0 rows affected (0.76 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1 values(); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable1;
This will produce the following output −
+-----------+ | isMarried | +-----------+ | NULL | +-----------+ 1 row in set (0.00 sec)
CASE 2 − When the ENUM gives first value from ENUM. Let us first create a table:
mysql> create table DemoTable2 (isMarried ENUM('YES','NO') NOT NULL); Query OK, 0 rows affected (0.57 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable2 values(); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable2;
This will produce the following output −
+-----------+ | isMarried | +-----------+ | YES | +-----------+ 1 row in set (0.00 sec)
Advertisements