- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements