Not NULL Constraints
A not NULL constraint specifies that a column cannot contain a null value. This means that new rows cannot be inserted or updated unless you specify a value for this column.
You can apply the not NULL constraint when you create a column in a new table, and when you add a column to an existing table (ALTER TABLE..ADD COLUMN
). You can also add or drop the not NULL constraint on an existing column:
ALTER TABLE t ALTER COLUMN x SET NOT NULL
ALTER TABLE t ALTER COLUMN x DROP NOT NULL
[SET | DROP] NOT NULL
clause does not validate whether column data conforms to the NOT NULL
constraint. Use ANALYZE_CONSTRAINTS
to check for constraint violations in a table. The not NULL constraint is implicitly applied to a column when you add the PRIMARY KEY (PK) constraint. When you designate a column as a primary key, you do not need to specify the not NULL constraint.
However, if you remove the primary key constraint, the not NULL constraint still applies to the column. Use the ALTER COLUMN..DROP NOT NULL
clause of the ALTER TABLE
statement to drop the not NULL constraint after dropping the primary key constraint.
The following statement enforces a not NULL constraint on the customer_key
column, specifying that the column cannot accept NULL values.
CREATE TABLE customer (customer_key INTEGER NOT NULL,
...
);