Saturday, July 23, 2011

NOT NULL Constraint


By default, a column can hold NULL. If you not want to allow NULL value in a column, you will want to place a constraint on this column specifying that NULL is now not an allowable value.
For example, in the following statement,
CREATE TABLE Customer
(SID integer NOT NULL,
Last_Name varchar (30) NOT NULL,
First_Name varchar(30));

Columns "SID" and "Last_Name" cannot include NULL, while "First_Name" can include NULL.
An attempt to execute the following SQL statement,
INSERT INTO Customer (Last_Name, First_Name) values ('Wong','Ken');
will result in an error because this will lead to column "SID" being NULL, which violates the NOT NULL constraint on that column.

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Deep's | Bloggerized by Deep - Deep's Templates | ElearSQL-Server