How to Insert Rows with NULL Values in SQL?
Last Updated :
09 Nov, 2021
In SQL, due to lack of data, we sometimes need to insert rows with NULL values in the tables. Here, the keyword NULL(without quotes) is used to represent no data. There are some key points of Null value:
- NULL value is different from a zero value.
- A NULL value is used to represent a missing value, but that it usually has one of three different interpretations:
- The value unknown (value exists but is not known)
- Value not available (exists but is purposely withheld)
- Attribute not applicable (undefined for this tuple)
- It is often not possible to determine which of the meanings is intended. Hence, SQL does not distinguish between the different meanings of NULL.
Syntax:
INSERT INTO TABLE_NAME values
(COLUMN_VALUE,NULL,........);
Step 1: Create a Database. For this use the below command to create a database named GeeksForGeeks.
Query:
CREATE DATABASE GeeksForGeeks
Output:

Step 2: Use the GeeksForGeeks database. For this use the below command.
Query:
USE GeeksForGeeks
Output:

Step 3: Create a table WORKER inside the database GeeksForGeeks. This table has 4 columns namely STUDENT_ID, STUDENT_NAME, STUDENT_STANDARD, ENGLISH, MATHS, and PHYSICS containing student id, student name, standard, and marks of various subjects.
Query:
CREATE TABLE WORKER(
W_NAME VARCHAR(20),
CITY VARCHAR(20),
AGE INT);
Output:

Step 4: Display the structure of the WORKER table.
Query:
EXEC SP_COLUMNS 'WORKER';
Output:

Step 5: Insert 10 rows into the WORKER table.
Query:
INSERT INTO WORKER VALUES('SAM','ONTARIO',NULL);
INSERT INTO WORKER VALUES('TIM',NULL,56);
INSERT INTO WORKER VALUES(NULL,'CAIRO',43);
INSERT INTO WORKER VALUES(NULL,'MUMBAI',NULL);
INSERT INTO WORKER VALUES(NULL,NULL,NULL);
Output:

Step 6: Display all the rows of the WORKER table including the 0(zero) values.
Query:
SELECT * FROM WORKER;
Output:

Thus, in this way, we can insert NULL values into a table.
Similar Reads
How to insert NULL value in SQLAlchemy? In this article, we will see how to insert NULL values into a PostgreSQL database using SQLAlchemy in Python. For demonstration purposes first, let us create a sample table using SQLAlchemy as shown below Creating a table using SQLAlchmey in PostgreSQL:Import necessary functions from SQLAlchemy pack
2 min read
Foreign Key with a Null Value in PostgreSQL PostgreSQL supports foreign keys to ensure referential integrity between tables. Nullable foreign keys add flexibility by allowing child table rows to either reference a parent table or have a NULL value, meaning no association. While this is useful in certain cases, managing nullable foreign keys c
6 min read
How to Filter Rows Without Null in a Column in SQL? Here we will see, how to filter rows without null in a column of an MS SQL Server's database table with the help of a SQL query using IS NOT NULL operator. For the purpose of demonstration, we will be creating a demo_orders table in a database called âgeeksâ. Creating the Database: Use the below SQL
2 min read
How to Use NULL Values Inside NOT IN Clause in SQL? In SQL, NULL holds a special status as it represents the absence of a value, making it fundamentally different from regular values. Unlike numbers or strings, NULL cannot be directly compared using operators like = or !=. This special status often leads to unexpected behavior in SQL queries, especia
4 min read
How to Insert Multiple Rows at Once in PL/SQL? As the volume and complexity of data continue to grow in modern systems, efficient data management techniques become important. One fundamental operation in database management is the insertion of multiple rows at once. In this article, we understand the techniques and methods available in PL/SQL fo
5 min read
PostgreSQL - Insert Multiple Values in Various Rows PostgreSQL, one of the most popular relational database management systems (RDBMS), is widely used for storing structured data in a tabular format, much like MySQL. In relational databases, data is stored in tables where each row represents a record and each column represents an attribute. One of th
3 min read