Wednesday, 28 August 2013

How to delete a null record in SQL Server or in SQL server how to delete rows where multiple columns have either null or Query to delete null or empty values from data table in SQL Server

Hi Friends, in this article I will explain about how to delete a null record in SQL Server or in SQL Server  how to delete rows where multiple columns have either null or Query to delete null or empty values from data table in SQL Server.
In previous article I explained some articles related SQL Server . Now I will explain about How to delete a null record in SQL Server. For that first create one table name it as USERS.

CREATE TABLE USERS (UserID INT identity, UserName String)
And insert values.i.e insert usernames
INSERT USERS VALUES(“Roja”)
INSERT USERS VALUES(“Kishore”)
INSERT USERS VALUES(NULL)
INSERT USERS VALUES(“Krish”)
INSERT USERS VALUES(“PurnaAnilKumar”)
INSERT USERS VALUES(NULL)

Check how many rows inserted
SELECT * FROM USERS
It will like below table.
UserID
UserName
1
Roja
2
Kishore
3
Null
4
Krish
5
PurnaAnilKumar
6
Null
If we use the below code the null values will not be deleted.
DELETE USERS WHERE UserName = NULL
The perfect code is as follows.
DELETE USERS WHERE UserName IS NULL
Now check the USERS table ,null values deleted or not
SELECT * FROM USERS
Then the output is

UserID
UserName
1
Roja
2
Kishore
4
Krish
5
PurnaAnilKumar

I think you like my blog why are waiting following me on facebook fan page Aspdotnet-roja

No comments:

Post a Comment

© 2012-2014 Aspdotnet-Kishore.blogspot.com. All Rights Reserved.
The content is copyrighted to Kishore and may not be reproduced on other websites without permission from the owner.