Sunday, 20 October 2013

SQL Server Query to Insert Null Values into a Table

SQL Server Query to Insert Null Values into a Table
CREATE TABLE CUSTOMERS ( CID INT PRIMARY KEY,CNAME VARCHAR(15) ,
 SEX VARCHAR(3),SAL DECIMAL(10,2), UNIQUE(CNAME));

INSERT CUSTOMERS VALUES(1,'JAN','M',10000.15);
--Inserting Null Value in to a Column with UNIQUE Constraint.
INSERT CUSTOMERS VALUES(2,'','F',20000.25);
INSERT CUSTOMERS VALUES(3,NULL,'F',30000.35);


SELECT*FROM CUSTOMERS ;

DROP TABLE CUSTOMERS;

NOTES :
-- Primary Key column will not Allow duplicate and Null Values.
-- Primary Key is a Table and Column level Constraint.
-- UNIQUE Constraint column will not allow duplicates but allows Null Values.
-- UNIQUE is a Table and Column level Constraint.

No comments:

Post a Comment

Follow Me by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts