What happens when I insert the value ‘NULL’ in an AUTO_INCREMENT MySQL column?


When we insert NULL value to AUTO_INCREMENT column, MySQL will return sequence number.

Example

mysql> Create table employee(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, Name Varchar(10));
Query OK, 0 rows affected (0.16 sec)

mysql> Insert into employee(id, Name) values(NULL, 'Gaurav');
Query OK, 1 row affected (0.07 sec)

mysql> Select * from employee;
+----+---------+
| id | Name    |
+----+---------+
| 1  | Gaurav  |
+----+---------+
1 row in set (0.00 sec)

Updated on: 20-Jun-2020

818 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements