Let’s create a new table
teachers, and insert a few rows of records in it.
Notice that we are able to enter a record with
NULL in the table. What if, we want to enforce that no new record should contain
NOT NULL option to add to a column definition while creating a table. It is one of the first
column constraints that we are going to explore in this course. Look at the
CREATE TABLE statement below.
We just have to add
NOT NULL next to the column name and data type, in the list of columns in
CREATE TABLE statement. This makes sure that no insert is allowed with
NULL in the specified column. Try the set of statements below:
Observe that on attempting an insert with
NULL, we get an error that expresses failing constraint.