ALTER TABLE .. DROP PRIMARY KEY
Applies to ✅ 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, Derby, Exasol, H2, HSQLDB, Hana, MariaDB, MySQL, Snowflake
ALTER TABLE t DROP PRIMARY KEY
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, Aurora Postgres, ClickHouse, CockroachDB, DuckDB, Firebird, Informix, MemSQL, Oracle, Redshift, SQLDataWarehouse, SQLServer, SQLite, Sybase, Teradata, Trino, Vertica, YugabyteDB
/* UNSUPPORTED */
Generated with jOOQ 3.20. Translate your own SQL on our website
Feedback
Do you have any feedback about this page? We'd love to hear it!