![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
When inserting a new row, should I include the columns that are null in the MySQL query?
If you do not specify the column list in insert statement then you can use below syntax −
insert into yourTableName values(NULL,yourValue,NULL,NULL,.....N);
Let us first create a table −
mysql> create table DemoTable1513 -> ( -> StudentId int, -> StudentName varchar(20) , -> StudentAge int, -> StudentCountryName varchar(20) -> ); Query OK, 0 rows affected (0.58 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1513 values(NULL,'Chris Brown',NULL,NULL); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1513 values(101,NULL,NULL,NULL); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1513 values(NULL,NULL,23,NULL); Query OK, 1 row affected (0.42 sec) mysql> insert into DemoTable1513 values(NULL,NULL,NULL,'US'); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1513;
This will produce the following output −
+-----------+-------------+------------+--------------------+ | StudentId | StudentName | StudentAge | StudentCountryName | +-----------+-------------+------------+--------------------+ | NULL | Chris Brown | NULL | NULL | | 101 | NULL | NULL | NULL | | NULL | NULL | 23 | NULL | | NULL | NULL | NULL | US | +-----------+-------------+------------+--------------------+ 4 rows in set (0.00 sec)
Advertisements