默认值
适用于 ✅ 开源版 ✅ 专业版 ✅ 企业版
列定义中的 DEFAULT
表达式定义了如果在 INSERT 语句中省略了该列,或者在 INSERT 或 UPDATE 中使用了显式的 DEFAULT
表达式,则该列应包含的值。默认情况下,在大多数方言中,这是 NULL
// Create a new table with a column with a default expression create.createTable("table") .column("column1", INTEGER.default_(1)) .execute();
要触发此 DEFAULT
表达式,您可以运行以下示例
// Insert a row using the default expression create.insertInto(table(name("table"))).defaultValues().execute();
方言支持
此示例使用 jOOQ
createTable("table") .column("column1", INTEGER.default_(1))
翻译成以下特定方言的表达式
Access, DB2, Firebird, Hana, Informix, Teradata
CREATE TABLE table ( column1 integer DEFAULT 1 )
ASE
CREATE TABLE table ( column1 int DEFAULT 1 NULL )
Aurora MySQL, Aurora Postgres, Derby, DuckDB, Exasol, H2, HSQLDB, MariaDB, MemSQL, MySQL, Postgres, Redshift, SQLDataWarehouse, SQLServer, Vertica, YugabyteDB
CREATE TABLE table ( column1 int DEFAULT 1 )
BigQuery
CREATE TABLE table ( column1 int64 DEFAULT 1 )
ClickHouse
CREATE TABLE table ( column1 Nullable(integer) DEFAULT 1 ) ENGINE Log()
CockroachDB
CREATE TABLE table ( column1 int4 DEFAULT 1 )
Databricks
CREATE TABLE table ( column1 int DEFAULT 1 ) TBLPROPERTIES( 'delta.columnMapping.mode' = 'name', 'delta.feature.allowColumnDefaults' = 'supported' )
Oracle, Snowflake
CREATE TABLE table ( column1 number(10) DEFAULT 1 )
SQLite
CREATE TABLE table ( column1 int DEFAULT (1) )
Sybase
CREATE TABLE table ( column1 int NULL DEFAULT 1 )
Trino
/* UNSUPPORTED */
使用 jOOQ 3.21 生成。早期 jOOQ 版本的支持可能有所不同。 在我们的网站上翻译您自己的 SQL
反馈
您对此页面有任何反馈吗? 我们很乐意听到您的反馈!