
- 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
Passing NULL to MySQL for auto increment?
Yes, we can pass NULL as in the below syntax −
insert into yourTableName values(NULL,yourValue1,yourValue2,...N);
Let us first create a table −
mysql> create table DemoTable1503 -> ( -> ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ClientName varchar(20), -> ClientAge int -> ); Query OK, 0 rows affected (0.45 sec)
Insert some records in the table using insert command. Since we have set NOT NULL above, it won’t affect auto_increment −
mysql> insert into DemoTable1503 values(NULL,'Chris',25); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1503 values(NULL,'David',28); Query OK, 1 row affected (0.37 sec) mysql> insert into DemoTable1503 values(NULL,'Bob',45); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1503 values(NULL,'Mike',57); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1503;
This will produce the following output. Auto Increment got printed in the same way (not null) −
+----------+------------+-----------+ | ClientId | ClientName | ClientAge | +----------+------------+-----------+ | 1 | Chris | 25 | | 2 | David | 28 | | 3 | Bob | 45 | | 4 | Mike | 57 | +----------+------------+-----------+ 4 rows in set (0.00 sec)
- Related Articles
- How to change auto increment number in MySQL?
- Set auto increment initial value for MySQL table using ALTER command
- Change the Auto Increment counter in MySQL?
- MySQL query to set my auto increment column ( id ) to zero or reset the value of auto increment field?
- How to make MySQL table primary key auto increment?
- Set custom Auto Increment with ZEROFILL in MySQL
- How to get the next auto-increment id in MySQL?
- How to set initial value and auto increment in MySQL?
- How to change auto increment number in the beginning in MySQL?
- How to handle fragmentation of auto increment ID column in MySQL?
- How to auto-increment value of tables to lower value in MySQL?
- How to add auto-increment to column in MySQL database using PhpMyAdmin?
- Two columns as primary key with auto-increment in MySQL?
- Set MySQL int column to auto increment by 1 beginning at 10000?
- Changing the current count of an Auto Increment value in MySQL?

Advertisements