SQL > Constraint > NOT NULL Constraint

By default, a column can hold NULL. If you do not want to allow NULL value in a column, you will want to place the NOT NULL constraint on this column. The NOT NULL constraint specifies that NULL is 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 ('Smith', 'Ken');

will result in an error because this will lead to column "SID" being NULL, which violates the NOT NULL constraint on that column.

Next: SQL DEFAULT Constraint

This page was last updated on June 19, 2023.




Copyright © 2024   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact