All versions: 3.11 | 3.10 | 3.9 | 3.8 | 3.7 | 3.6 | 3.5 | 3.4 | Development versions: 3.12

jOOQ currently supports the following ALTER statements (SQL examples in PostgreSQL syntax):

Indexes

// Renaming the index
create.alterIndex("old_index").renameTo("new_index").execute();

// Renaming the index only if it exists (not all databases support this)
create.alterIndexIfExists("old_index").renameTo("new_index").execute();
// Renaming the schema
create.alterSchema("old_schema").renameTo("new_schema").execute();

// Renaming the schema only if it exists (not all databases support this)
create.alterSchemaIfExists("old_schema").renameTo("new_schema").execute();
// Renaming the sequence
create.alterSequence("old_sequence").renameTo("new_sequence").execute();

// Renaming the sequence only if it exists (not all databases support this)
create.alterSequenceIfExists("old_sequence").renameTo("new_sequence").execute();

// Restarting the sequence
create.alterSequence(S_AUTHOR_ID).restart().execute();
create.alterSequence(S_AUTHOR_ID).restartWith(n).execute();

Tables

These statements alter the table itself:

// Renaming the table
create.alterTable("old_table").renameTo("new_table").execute();

// Renaming the table only if it exists (not all databases support this)
create.alterTableIfExists("old_table").renameTo("new_table").execute();

These statements alter / add / drop columns and their types:

// Adding columns
create.alterTable(AUTHOR).add(AUTHOR.TITLE, VARCHAR.length(5)).execute();
create.alterTable(AUTHOR).add(AUTHOR.TITLE, VARCHAR.length(5).nullable(false)).execute();

// Altering columns
create.alterTable(AUTHOR).alter(TITLE).defaultValue("no title").execute();
create.alterTable(AUTHOR).alter(TITLE).set(VARCHAR.length(5)).execute();
create.alterTable(AUTHOR).alter(TITLE).set(VARCHAR.length(5).nullable(false)).execute();
create.alterTable(AUTHOR).renameColumn("old_column").to("new_column").execute();

// Dropping columns
create.alterTable(AUTHOR).drop(TITLE).execute();

These statements alter / add / drop constraints:

// Adding constraints
create.alterTable(BOOK).add(constraint("PK_BOOK").primaryKey(BOOK.ID)).execute();
create.alterTable(BOOK).add(constraint("UK_TITLE").unique(BOOK.TITLE)).execute();
create.alterTable(BOOK).add(
   constraint("FK_AUTHOR_ID")
  .foreignKey(BOOK.AUTHOR_ID)
  .references(AUTHOR, AUTHOR.ID)).execute();
create.alterTable(BOOK).add(
   constraint("CHECK_PUBLISHED_IN")
  .check(BOOK.PUBLISHED_IN.between(1900).and(2000))).execute();

// Altering constraints
create.alterTable(BOOK).renameConstraint("old_constraint").to("new_constraint").execute();

// Dropping constraints
create.alterTable(AUTHOR).dropConstraint("UK_TITLE").execute();
// Renaming the view
create.alterView("old_view").renameTo("new_view").execute();

// Renaming the view only if it exists (not all databases support this)
create.alterViewIfExists("old_view").renameTo("new_view").execute();
The jOOQ Logo