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

ALTER TABLE .. DROP FOREIGN KEY

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

A FOREIGN KEY constraint can be dropped from the table using the ALTER TABLE's DROP FOREIGN KEY clause:

// Drop specific types of constraints
create.alterTable("table").dropForeignKey("fk").execute();

Dialect support

This example using jOOQ:

alterTable("t").dropForeignKey("c")

Translates to the following dialect specific expressions:

ASE, Access, Aurora Postgres, CockroachDB, DB2, Derby, Exasol, Firebird, H2, HSQLDB, Hana, Informix, Oracle, Postgres, Redshift, SQLDataWarehouse, SQLServer, Snowflake, Sybase, Teradata, Vertica, YugabyteDB

ALTER TABLE t DROP CONSTRAINT c

Aurora MySQL, MariaDB, MySQL

ALTER TABLE t DROP FOREIGN KEY c

BigQuery

ALTER TABLE t DROP PRIMARY KEY

ClickHouse, DuckDB, MemSQL, SQLite, Trino

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

References to this page

Feedback

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

The jOOQ Logo