Thursday, 2 April 2015

How to Insert or Delete Blank or Null Values in to a SQL Table

SQL DELETE Statement
The DELETE statement is used to delete Rows or Records in a Table.

SQL DELETE Syntax:

DELETE FROM table_name WHERE some_column=some_value

Note: 
Notice the WHERE clause in the DELETE syntax. The WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted!


Example:


Create Table EMPLOYEE

(
EID INT,
EMPNAME VARCHAR(25) , 
DEPT VARCHAR(25),
DOJ DATE , 
SAL DECIMAL(7,2)
)

GO

Entering Records with Null or Blank Values :


INSERT INTO EMPLOYEE 

SELECT 123,'REDDY','TECH','02-20-2014',25450.25 UNION ALL
SELECT 234,'RAMYA','PROD','03-20-2014',35450.25 UNION ALL

SELECT '','RAJU','MARKETING','04-20-2014',45450.25 UNION ALL 'EID as Blank Value

SELECT NULL,'KAJAL','CRM','04-20-2014',55450.25 UNION ALL 'EID as NULL Value
SELECT 456,'SRUTHI','','05-20-2014',65450.25 'DEPT as BlankValue

GO


EID
EMPNAME
DEPT
DOJ
SAL
123
REDDY
TECH
2/20/2014
25450.25
234
RAMYA
PROD
3/20/2014
35450.25
0
RAJU
MARKETING
4/20/2014
45450.25
NULL
KAJAL
CRM
4/20/2014
55450.25
456
SRUTHI

5/20/2014
65450.25

Deleting Records with Null or Blank Values :


DELETE FROM EMPLOYEE WHERE  EID = '' OR EID IS NULL OR DEPT=''


Note :

When you pass Blank value to a Numeric Field , it will take '0' as Value.
When you pass Blank value to a Text Field , it will take '' as Value.
To delete a record with NULL value , we have to use IS NULL condition. No Logical operator can be applicable.

No comments:

Post a Comment

Follow Me by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts