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 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, 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, BigQuery, 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

References to this page

Feedback

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

The jOOQ Logo