MainMenu

Home Core Java Overview Maven Tutorials

Sunday, 15 January 2017

Insert & Fetch Null values in Database Table with example

NULL Values :

A value of NULL indicates that the value is unknown. A value of NULL is different
from an empty or zero value. No two null values are equal.
Comparisons between two null values, or between a NULL and any other value,
return unknown because the value of each NULL is unknown.


Inserting Null Values In MySQL:



Consider the below table :
Order_idNameAmount
O001chandan2500
O002Adhiraj3500

Now if you want to insert the null values then your query will be :


QUERY :
INSERT INTO Order(order_id)
values("O003")
Result :
Order_idNameAmount
O001chandan2500
O002Adhiraj3500
O003NULLNULL

Note : if you want to insert the blank space instead of Null values then your query will be :


Query :

INSERT INTO Order(order_id, Name)
values("O004", "" )



Result :
Order_idNameAmount
O001chandan2500
O002Adhiraj3500
O003NULLNULL
O0040

Insert Null value in SQL

Consider the below table :
Order_idNameAmount
O001chandan2500
O002Adhiraj3500

Note : Table column property should not set to NOT NULL.

Now if you want to insert the null values then your query will be :


QUERY :
Insert Into Order(order_id, name, Amount)
Values (null, null, null)
Result :
Order_idNameAmount
O001chandan2500
O002Adhiraj3500
nullnullnull
Get blank rows consider the below table
Order_idNameAmount
O001chandan2500
O002Adhiraj3500
O003
O004
O005NULLNULL

Query to fetch blank rows in MySql

Select *
from order
Where Name = ""
Result :

Order_idNameAmount
O003
O004

Query to fetch NULL rows in MySql

Select *
from order
Where Name IS NULL
Result :

Order_idNameAmount
O005NULLNULL

Query to fetch NOT NULL rows in MySql

Select *
from order
Where Name IS NOT NULL
Result :

Order_idNameAmount
O001chandan2500
O002Adhiraj3500
O003
O004
Get blank rows consider the below table
Order_idNameAmount
O001chandan2500
O002Adhiraj3500
O003
O004
O005NULLNULL

Query to fetch blank rows in Sql

Select *
from order
Where Name = ""
Result :

Order_idNameAmount
O003
O004

Query to fetch NULL rows in Sql

Select *
from order
Where Name IS NULL
Result :

Order_idNameAmount
O005NULLNULL

Query to fetch NOT NULL rows in Sql

Select *
from order
Where Name IS NOT NULL
Result :

Order_idNameAmount
O001chandan2500
O002Adhiraj3500
O003
O004

Tag:Query to add null values in SQl,Query to add null values in mysql, SQL Null values with example,SQL Query to get Null Rows, SQL Query to get NOT Null Rows

No comments:

Post a Comment