Can we skip a column name while inserting values in MySQL?


Yes, we can do that. Let us first create a table −

mysql> create table DemoTable
   -> (
   -> StudentName varchar(100),
   -> StudentAge int
   -> );
Query OK, 0 rows affected (0.72 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable(StudentAge) values(23);
Query OK, 1 row affected (0.22 sec)

mysql> insert into DemoTable(StudentName) values('John');
Query OK, 1 row affected (0.21 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output. NULL will get inserted for the skipped column values −

+-------------+------------+
| StudentName | StudentAge |
+-------------+------------+
| NULL        |         23 |
| John        |       NULL |
+-------------+------------+
2 rows in set (0.00 sec)

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

579 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements