【问题标题】:is it possible to define index in create table statement itself in db2?是否可以在 db2 中的 create table 语句本身中定义索引?
【发布时间】:2021-08-26 11:46:40
【问题描述】:

我可以在 CREATE TABLE 语句上创建索引吗? IE。我可以在创建表时为表定义索引吗?我的意思是在create语句SQL命令上创建索引

【问题讨论】:

  • 您将拥有主键或唯一约束的隐式索引。

标签: sql db2 create-table


【解决方案1】:

创建表时可以通过添加UNIQUE约束来创建唯一索引;引擎将使用唯一索引实现约束。请注意,在 DB2 中,列必须是 NOT NULL 才能参与 UNIQUE 约束。

例如:

create table t (
  a int,
  b varchar(10) not null,
  c date not null,
  constraint uq1 unique (b, c)
);

约束创建一个包含bc 列的索引。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-08
    • 2019-11-27
    • 2011-06-09
    • 1970-01-01
    • 1970-01-01
    • 2020-06-11
    • 1970-01-01
    • 2012-12-12
    相关资源
    最近更新 更多