- Trending Categories
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
Is it necessary to add DEFAULT NULL in MySQL?
No, it isn’t necessary because without adding DEFAULT NULL, it gives NULL value. For example, let’s say you haven’t added DEFAULT NULL and inserted a record with no value, then the result would display the NULL value as the inserted value.
Let us first create a table −
mysql> create table DemoTable ( FirstName varchar(100) ); Query OK, 0 rows affected (0.57 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-----------+ | FirstName | +-----------+ | Chris | | NULL | | NULL | | David | +-----------+ 4 rows in set (0.00 sec)
Advertisements