ALTER TABLE ALTER COLUMN SET NOT NULL

Sets a column to NOT NULL, disallowing null values in future writes.

Category: ddl

Syntax

ALTER TABLE <table> ALTER COLUMN <column> SET NOT NULL

Description

## Overview Changes a column's nullability from nullable to NOT NULL. After this operation, any write that attempts to insert a NULL value for this column will be rejected by the Delta writer. ## Behavior - The column must exist in the table's current schema. If the column is not found, the command fails. - The operation sets the `nullable` flag to `false` in the Delta schema metadata. - This is a metadata-only commit. No data files are rewritten or validated. - The COLUMN keyword after ALTER is optional. - Existing data is not scanned for null values. If the column already contains NULLs from previous writes, those rows remain. Only future writes are constrained. ## Compatibility Setting a column to NOT NULL is compatible with all Delta readers. Older Parquet files that contain NULL values for this column are still readable; the constraint only affects writes going forward.

Parameters

NameTypeDescription
tableFully qualified table name or registered table name. The table must be registered in the current session.
column_nameColumn to alter.

Examples

-- Require a column to be non-null
ALTER TABLE warehouse.sales.orders ALTER COLUMN customer_id SET NOT NULL;
-- Set NOT NULL without the optional COLUMN keyword
ALTER TABLE warehouse.sales.products ALTER sku SET NOT NULL;
-- Enforce non-null on a timestamp column
ALTER TABLE warehouse.sales.events ALTER COLUMN event_time SET NOT NULL;

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →