|
SQL also allow the user to define a number of constraints on attribute values (domain constraints):
|
|
The NOT NULL constraint is commonly used along with the primary key and the unique constraints to prevent the use of NULL values in key attributes
Example:
CREATE TABLE test6 ( ssn CHAR(9) NOT NULL, fname CHAR(30), lname CHAR(30) ); |
But this insert will fail:
|
Example:
CREATE TABLE test7 ( ssn CHAR(9) NOT NULL, salary DECIMAL(6,2) DEFAULT 5000 // Minimum wage ); |
The tuple does not contain the salary attribute
|
Example:
CREATE TABLE test8
(
ssn CHAR(9) NOT NULL,
dno INTEGER CHECK (dno > 0 and dno < 21)
);
|
|