How to insert null in MySQL

Here we will see how we can insert NULL in the MySQL table. Sometimes we don’t have to put anything in some columns while inserting data in MySQL, in that case, we have to insert null to those columns.

Insert null value in MySQL

To insert a null value simply put null in the place of the value. Before inserting null you have to make sure that column is not the primary key or Not Null column, otherwise, MySQL will throw an error.

To check in which column we can insert null, we can check the table structure by using the describe statement of MySQL.

Describe table_name;

describe employee;
| Field       | Type        | Null | Key | Default | Extra |
| id          | int         | NO   | PRI | NULL    |       |
| fname       | varchar(50) | NO   |     | NULL    |       |
| mname       | varchar(50) | YES  |     | NULL    |       |
| lname       | varchar(50) | NO   |     | NULL    |       |
| designation | varchar(50) | NO   |     | NULL    |       |

Here we have the employee table, in this table, we have mname column in which we can insert null value, rest columns can not have null values.

Below is an example of inserting a Null value in a MySQL table.

 insert into employee values(100,'steve',null,'cook','Analyst');

To check whether null has been inserted, we can use a select statement

select * from employee where id=100;
Scroll to Top