Sunday, October 20, 2013

How to Insert Null Values into a Table in SQL Server

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

INSERT CUSTOMERS VALUES(1,'JAN','M',10000.15);
--Inserting Blank value and a Null Value into 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

Hi User, Thank You for visiting My Blog. If you wish, please share your genuine Feedback or comments only related to this Blog Posts. It is my humble request that, please do not post any Spam comments or Advertising kind of comments, which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose we have a sample Sales data, which is stored with Monthly Snapsh...

Popular Posts from this Blog