Available in versions: Dev (3.21) | Latest (3.20) | 3.19 | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11

ALTER TABLE .. ALTER COLUMN .. SET NOT NULL

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

A column can be set to NOT NULL using the ALTER TABLE's NOT NULL clause on a column:

// Specify the not null constraint on a column
// Note that in some but not all dialects, the data type of the column needs to be known to jOOQ and the RDBMS
create.alterTable("table").alter(field("column", VARCHAR(10))).setNotNull().execute();

The existing data in the column must not contain any nulls or an error will be raised.

Dialect support

This example using jOOQ:

alterTable("t").alter(field("c", VARCHAR(10))).setNotNull()

Translates to the following dialect specific expressions:

ASE, Oracle

ALTER TABLE t MODIFY c NOT NULL

Aurora MySQL, MariaDB, MySQL

ALTER TABLE t CHANGE COLUMN c c varchar(10) NOT NULL

Aurora Postgres, CockroachDB, DB2, Derby, DuckDB, Firebird, H2, HSQLDB, Postgres, Snowflake, YugabyteDB

ALTER TABLE t ALTER c SET NOT NULL

Databricks, Vertica

ALTER TABLE t ALTER COLUMN c SET NOT NULL

Exasol

ALTER TABLE t MODIFY c SET NOT NULL

MemSQL

ALTER TABLE t MODIFY c varchar(10) NOT NULL

Access, BigQuery, ClickHouse, Hana, Informix, Redshift, SQLDataWarehouse, SQLServer, SQLite, Sybase, Teradata, Trino

/* UNSUPPORTED */
Generated with jOOQ 3.21. Translate your own SQL on our website

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo