可用版本: Dev (3.21) | 最新 (3.20) | 3.19 | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11

ALTER TABLE .. ADD COLUMNS

适用于 ✅ 开源版   ✅ 专业版   ✅ 企业版

如果需要原子性地添加多个列,并且为了节省服务器往返次数,一些 RDBMS 支持使用单个 ALTER TABLE 语句向表中添加多个列。

// Adding several columns to a table in one go
create.alterTable("table").add(field(name("column1"), INTEGER), field(name("column2"), INTEGER)).execute();

方言支持

此示例使用 jOOQ

alterTable("t").add(field("c1", INTEGER), field("c2", INTEGER))

翻译成以下特定方言的表达式

ASE

ALTER TABLE t ADD 
  c1 int NULL,
  c2 int NULL

Aurora MySQL, Aurora Postgres, MariaDB, MemSQL, MySQL, Postgres, YugabyteDB

ALTER TABLE t ADD c1 int,
ADD c2 int

BigQuery

ALTER TABLE t ADD COLUMN c1 int64,
ADD COLUMN c2 int64

ClickHouse

ALTER TABLE t ADD COLUMN c1 Nullable(integer),
ADD COLUMN c2 Nullable(integer)

CockroachDB

ALTER TABLE t ADD c1 int4,
ADD c2 int4

Databricks

ALTER TABLE t ADD COLUMN (
  c1 int,
  c2 int
)

DB2

ALTER TABLE t ADD c1 integer
ADD c2 integer

Firebird, Teradata

ALTER TABLE t ADD c1 integer,
ADD c2 integer

H2

ALTER TABLE t ADD (
  c1 int,
  c2 int
)

Hana, Informix

ALTER TABLE t ADD (
  c1 integer,
  c2 integer
)

Oracle, Snowflake

ALTER TABLE t ADD (
  c1 number(10),
  c2 number(10)
)

SQLDataWarehouse, SQLServer

ALTER TABLE t ADD 
  c1 int,
  c2 int

Access, Derby, DuckDB, Exasol, HSQLDB, Redshift, SQLite, Sybase, Trino, Vertica

/* UNSUPPORTED */
使用 jOOQ 3.21 生成。早期 jOOQ 版本的支持可能有所不同。 在我们的网站上翻译您自己的 SQL

反馈

您对此页面有任何反馈吗? 我们很乐意听到!

The jOOQ Logo