Insertion in a MySQL table with only a single column set as auto_increment?

MySQLMySQLi Database

Let us first create a table −

mysql> create table DemoTable
   -> (
   -> StudentId int NOT NULL AUTO_INCREMENT,
   -> PRIMARY KEY(StudentId)
   -> );
Query OK, 0 rows affected (0.60 sec)

Insert some records in the table using insert command. Here, we have inserted a value, but since it is AUTO_INCREMENT, therefore, the default value would be visible −

mysql> insert into DemoTable(StudentId) values(0);
Query OK, 1 row affected (0.18 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output. The default AUTO_INCREMENT value 1 as the first value is visible −

+-----------+
| StudentId |
+-----------+
|         1 |
+-----------+
1 row in set (0.00 sec)
raja
Published on 09-Jul-2019 14:38:59
Advertisements