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
ALTER TABLE .. DROP PRIMARY KEY
Supported by ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
A PRIMARY KEY constraint can be dropped from the table using the ALTER TABLE's DROP PRIMARY KEY clause:
// Drop specific types of constraints
create.alterTable("table").dropPrimaryKey().execute();
Dialect support
This example using jOOQ:
alterTable("t").dropPrimaryKey()
Translates to the following dialect specific expressions:
Aurora MySQL, BigQuery, DB2, Databricks, Exasol, H2, HSQLDB, Hana, MariaDB, MySQL, Snowflake
ALTER TABLE t DROP PRIMARY KEY
Aurora Postgres, Postgres
DO $$
DECLARE
n varchar;
BEGIN
n := (
SELECT constraint_name
FROM information_schema.table_constraints
WHERE (
(table_name = 't')
AND (constraint_type = 'PRIMARY KEY')
)
);
EXECUTE ('alter table "t" drop constraint ' || n);
END;
$$
ASE, Access, ClickHouse, CockroachDB, DuckDB, Firebird, Informix, MemSQL, Oracle, Redshift, SQLDataWarehouse, SQLServer, SQLite, Spanner, Sybase, Teradata, Trino, Vertica, YugabyteDB
/* UNSUPPORTED */
Generated with jOOQ 3.21. Support in older jOOQ versions may differ. Translate your own SQL on our website
Feedback
Do you have any feedback about this page? We'd love to hear it!