NOT NULL

SQL NOT NULL Keyword

The NOT NULL constraint ensures that a column cannot have a NULL value. This means that the column must always contain a value when a record is inserted or updated.

Tutorials dojo strip

SQL NOT NULL Syntax

SQL

To add a NOT NULL constraint to an existing column in some databases:

SQL

Note: The MODIFY syntax may vary depending on the SQL engine.

SQL NOT NULL on CREATE TABLE Example

This query creates a new table DoctorsBackup where the first_name and last_name columns must have values.

SQL

SQL NOT NULL on Existing Table Example

This query alters the Students table to ensure the email column cannot have NULL values.

SQL

Note: This example does not work in our TechKubo playground (SQLite), because SQLite does not support modifying existing columns to add NOT NULL directly.

Tip: Always use NOT NULL on columns where a missing value would break your application logic or data integrity.

SQL NOT NULL Labs

Tutorials dojo strip