- 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
Can MySQL INT type be non-zero NULL?
You can set the INT column to value NULL.The column INT type a nullable column. The syntax is as follows:
INSERT INTO yourTableName(yourIntColumnName) values(NULL);
To understand the above syntax, let us create a table. The query to create a table is as follows:
mysql> create table nullableIntDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Price int, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.80 sec)
Insert the record as NULL for a int column ‘Price’. The query is as follows:
mysql> insert into nullableIntDemo(Price) values(NULL); Query OK, 1 row affected (0.11 sec) mysql> insert into nullableIntDemo(Price) values(100); Query OK, 1 row affected (0.15 sec) mysql> insert into nullableIntDemo(Price) values(200); Query OK, 1 row affected (0.12 sec) mysql> insert into nullableIntDemo(Price) values(NULL); Query OK, 1 row affected (0.13 sec) mysql> insert into nullableIntDemo(Price) values(NULL); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement. The query is as follows:
mysql> select *from nullableIntDemo;
The following is the output:
+----+-------+ | Id | Price | +----+-------+ | 1 | NULL | | 2 | 100 | | 3 | 200 | | 4 | NULL | | 5 | NULL | +----+-------+ 5 rows in set (0.00 sec)
Look at the above sample output, in MySQL int column is a nullable.
Advertisements