- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Insert NULL value into INT column in MySQL?
152 Lectures 16 hours
87 Lectures 5.5 hours
You can insert NULL value into an int column with a condition i.e. the column must not have NOT NULL constraints. The syntax is as follows.
INSERT INTO yourTableName(yourColumnName) values(NULL);
To understand the above syntax, let us first create a table. The query to create a table is as follows.
mysql> create table InsertNullDemo -> ( -> StudentId int, -> StudentName varchar(100), -> StudentAge int -> ); Query OK, 0 rows affected (0.53 sec)
Here is the query to insert NULL whenever you do not pass any value for column. Here this column is StudentAge. MySQL inserts null value by default. The query to insert records is as follows.
mysql> insert into InsertNullDemo(StudentId,StudentName) values(101,'Mike'); Query OK, 1 row affected (0.19 sec) mysql> insert into InsertNullDemo values(101,'Mike',NULL); Query OK, 1 row affected (0.24 sec)
Display all records from the table to check the NULL value is inserted or not into INT column. The query is as follows.
mysql> select *from InsertNullDemo;
The following is the output displaying NULL in INT column.
+-----------+-------------+------------+ | StudentId | StudentName | StudentAge | +-----------+-------------+------------+ | 101 | Mike | NULL | | 101 | Mike | NULL | +-----------+-------------+------------+ 2 rows in set (0.00 sec)
- Insert default into not null column if value is null in MySQL?
- Java application to insert null value into a MySQL database?
- Insert NULL value into database field with char(2) as type in MySQL?
- How to insert NULL into char(1) in MySQL?
- How to insert DATE into a MySQL column value using Java?
- How do I insert a NULL value in MySQL?
- What happens when I insert the value ‘NULL’ in an AUTO_INCREMENT MySQL column?
- How to insert NULL keyword as a value in a character type column of MySQL table having NOT NULL constraint?
- How to insert own values into auto_increment column in MySQL?
- MySQL insert a value to specific row and column
- What MySQL returns if I insert invalid value into ENUM?
- How do I INSERT INTO from one MySQL table into another table and set the value of one column?
- How can I insert a value in a column at the place of NULL using MySQL COALESCE() function?
- How can we use INSERT() function to insert a new string into the value of a column of MySQL table?
- Can MySQL INT type be non-zero NULL?