
- 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
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)
- Related Articles
- Display only NOT NULL values from a column with NULL and NOT NULL records in MySQL
- Working with NULL and IS NOT NULL in MySQL
- What is MySQL NOT NULL constraint and how can we declare a field NOT NULL while creating a table?
- Selecting rows using the ENUM field in MySQL
- Why MySQL NOT NULL shouldn’t be added to primary key field?
- How do you check if a field is NOT NULL with Eloquent?
- Display the result with not null value first and then with null value in MySQL
- MySQL syntax not evaluating with not equal operator in presence of null?
- How to update a field with a particular value if it is null in MySQL?
- Check for NULL or NOT NULL values in a column in MySQL
- Check whether a field is empty or null in MySQL?
- Select a field and if it's null, select another with MySQL?
- How do I update NULL values in a field in MySQL?
- Difference Between MySql NULL and IS NOT NULL?
- Conditional NOT NULL case MySQL?

Advertisements