

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I insert a NULL value in MySQL?
To insert a NULL value, you can use UPDATE command. Following is the syntax −
UPDATE yourTableName SET yourColumnName=NULL;
Let us first create a table −
mysql> create table insertNullValue -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ClientName varchar(100), -> ClientCountryName varchar(20) -> ); Query OK, 0 rows affected (0.54 sec)
Following is the query to insert some records in the table using insert command −
mysql> insert into insertNullValue(ClientName,ClientCountryName) values('Larry','US'); Query OK, 1 row affected (0.19 sec) mysql> insert into insertNullValue(ClientName,ClientCountryName) values('David','AUS'); Query OK, 1 row affected (0.09 sec) mysql> insert into insertNullValue(ClientName,ClientCountryName) values('Bob','UK'); Query OK, 1 row affected (0.17 sec)
Following is the query to display all records from the table using select statement −
mysql> select * from insertNullValue;
This will produce the following output −
+----+------------+-------------------+ | Id | ClientName | ClientCountryName | +----+------------+-------------------+ | 1 | Larry | US | | 2 | David | AUS | | 3 | Bob | UK | +----+------------+-------------------+ 3 rows in set (0.00 sec)
Following is the query to insert NULL value for a column −
mysql> update insertNullValue set ClientCountryName=NULL; Query OK, 3 rows affected (0.19 sec) Rows matched: 3 Changed: 3 Warnings: 0
Let us check the NULL value is inserted for the column ‘ClientCountryName’ or not. Following is the query −
mysql> select * from insertNullValue;
This will produce the following output displaying the NULL values −
+----+------------+-------------------+ | Id | ClientName | ClientCountryName | +----+------------+-------------------+ | 1 | Larry | NULL | | 2 | David | NULL | | 3 | Bob | NULL | +----+------------+-------------------+ 3 rows in set (0.00 sec)
- Related Questions & Answers
- Insert NULL value into INT column in MySQL?
- How do I modify a MySQL column to allow NULL?
- How do I update NULL values in a field in MySQL?
- How can I insert a value in a column at the place of NULL using MySQL COALESCE() function?
- How do I check whether a field contains null value in MongoDB?
- Java application to insert null value into a MySQL database?
- Insert default into not null column if value is null in MySQL?
- What happens when I insert the value ‘NULL’ in an AUTO_INCREMENT MySQL column?
- How do I insert elements in a Java list?
- How do I check if a column is empty or null in MySQL?
- How do I insert multiple values in a column with a single MySQL query?
- How can I insert default value in MySQL ENUM data type?
- How to insert NULL keyword as a value in a character type column of MySQL table having NOT NULL constraint?
- How can I set 0 if a query returns a null value in MySQL?
- How to do a batch insert in MySQL?
Advertisements