Skip to main content
The NOT NULL specifies a column may not contain values.

Details

  • INSERT or UPDATE statements containing NULL values are rejected. This includes INSERT statements that do not include values for any columns that do not have a .
For example, if the table foo has columns a and b (and b does not have a DEFAULT VALUE), when you run the following command:
CockroachDB tries to write a NULL value into column b. If that column has the NOT NULL constraint, the INSERT statement is rejected.
  • To add the NOT NULL constraint to an existing table column, use the statement.
  • For more information about NULL, see .

Syntax

You can only apply the NOT NULL constraint to individual columns. not_null_column_level syntax diagram
ParameterDescription
table\_nameThe name of the table you’re creating.
column\_nameThe name of the constrained column.
column\_typeThe constrained column’s .
column\_constraintsAny other column-level you want to apply to this column.
column\_defDefinitions for any other columns in the table.
table\_constraintsAny table-level you want to apply.

Usage example

See also