NOT NULL
The NOT NULL
constraint ensures that a column cannot have a NULL
value. This means that every row in the table must have a value for that column. For example, consider a table employees
with a column employee_id
that should not be NULL
. The NOT NULL
constraint can be applied as follows:
sql
CREATE TABLE employees (
employee_id INT NOT NULL,
first_name VARCHAR(50),
last_name VARCHAR(50)
);
In this case, the employee_id
column must have a value for every row in the employees
table.
name | type |
employee_id | INT |
first_name | VARCHAR(50) |
last_name | VARCHAR(50) |
In the table above, each row has a value for the employee_id
column, as required by the NOT NULL
constraint.