Can we skip column when inserting into MySQL?

MySQLMySQLi Database

If your first column is AUTO_INCREMENT, then you can skip the column and place the value NULL. Let us first create a table −

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

Insert some records in the table using insert command. Here, we have skipped the first column, since it is AUTO_INCREMENT −

mysql> insert into DemoTable values(NULL,'Robert',21);
Query OK, 1 row affected (0.21 sec)
mysql> insert into DemoTable values(NULL,'Sam',22);
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable values(NULL,'Bob',24);
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable values(NULL,'Carol',20);
Query OK, 1 row affected (0.14 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+-----------+------------------+------------+
| StudentId | StudentFirstName | StudentAge |
+-----------+------------------+------------+
|         1 | Robert           |         21 |
|         2 | Sam              |         22 |
|         3 | Bob              |         24 |
|         4 | Carol            |         20 |
+-----------+------------------+------------+
4 rows in set (0.00 sec)
raja
Published on 01-Oct-2019 11:21:54
Advertisements