
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- Insert NULL value into INT column in MySQL?
- What happens when I insert the value ‘NULL’ in an AUTO_INCREMENT MySQL column?
- How can I insert a value in a column at the place of NULL using MySQL COALESCE() function?
- Insert default into not null column if value is null in MySQL?
- How do I update NULL values in a field in MySQL?
- Java application to insert null value into a MySQL database?
- How do I modify a MySQL column to allow NULL?
- How do I check whether a field contains null value in MongoDB?
- How to insert NULL keyword as a value in a character type column of MySQL table having NOT NULL constraint?
- 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 can I set 0 if a query returns a null value in MySQL?
- How to insert NULL into char(1) in MySQL?
- How do I select data that does not have a null record in MySQL?

Advertisements