根据文档,为了使用 JOOQ 创建表:
context.createTable("table")
.column("column1", INTEGER)
.column("column2", VARCHAR(10).nullable(false))
.constraints(
primaryKey("column1"),
unique("column2"),
foreignKey("column2").references("some_other_table"),
check(field(name("column2")).like("A%"))
)
.execute();
但是,似乎也可以在创建表时声明索引:
context.createTable("table")
.column("column1", INTEGER)
.column("column2", VARCHAR(10).nullable(false))
.constraints(
primaryKey("column1"),
unique("column2"),
foreignKey("column2").references("some_other_table"),
check(field(name("column2")).like("A%"))
)
.indexes(...indices)
.execute();
我在说明如何执行此操作的文档中找不到任何内容。
以这种方式声明索引的正确方法是什么?
最佳答案
jOOQ 3.15 还不支持这种特殊的语法: https://github.com/jOOQ/jOOQ/issues/9243
您可以通过多种方式自行实现,例如:
或者,您可以使用 jOOQ DSL API 运行两个单独的语句:
创建表
创建索引
关于java - JOOQ 用索引创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70072756/