
- 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
How to insert a row into a table that has only a single autoincrement column?
You can easily insert a row into a table that has only a single auto increment column. The syntax is as follows −
insert into yourTableName set yourColumnName =NULL;
You can use the below syntax −
insert into yourTableName values(NULL);
To understand the above syntax, let us create a table. The query to create a table is as follows −
mysql> create table singleAutoIncrementColumnDemo -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY -> ); Query OK, 0 rows affected (0.62 sec)
Insert some records in the table using insert command. The query is as follows −
mysql> insert into singleAutoIncrementColumnDemo set UserId =NULL; Query OK, 1 row affected (0.18 sec) mysql> insert into singleAutoIncrementColumnDemo values(NULL); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement. The query is as follows −
mysql> select *from singleAutoIncrementColumnDemo;
Here is the output −
+--------+ | UserId | +--------+ | 1 | | 2 | +--------+ 2 rows in set (0.00 sec)
- Related Articles
- How to insert only a single column into a MySQL table with Java?
- How can we insert a new row into a MySQL table?
- How to insert new row into table at a certain index using jQuery?
- MySQL trigger to insert row into another table?
- How to insert a row into a ResultSet object using JDBC?
- How can we use INSERT() function to insert a new string into the value of a column of MySQL table?
- How to insert an array of values in a MySQL table with a single INSERT?
- How to insert multiple rows in a table using a single INSERT command in program?
- Insertion in a MySQL table with only a single column set as auto_increment?
- How to insert only those records that does not exist in a MySQL table?
- How to insert a DATALINK object into a table using JDBC?
- MySQL insert a value to specific row and column
- How to insert into two tables using a single MySQL query?
- Insert JSON into a MySQL table?
- How can we delete a single row from a MySQL table?

Advertisements