首页 文章

Oracle alter table drop constraint drop index在语法上是否有效?

提问于
浏览
2

我有Oracle 11.2.0.2.0和一个由以下脚本创建的具有唯一约束的表:

create table foo (id varchar(26) not null, name varchar(50) not null);
    alter table foo add constraint pk_foo primary key (id);
    /**/
    alter table foo add constraint un_foo unique (name);

我需要删除唯一约束,这很容易:

alter table foo drop constraint un_foo;

问题是:当数据库在SQL Developer中备份然后恢复时, un_foo 唯一索引由 /**/ 行的显式命令创建:

CREATE UNIQUE INDEX un_foo ON foo (name);

上面的alter命令不会删除这种显式创建的索引 . 我意识到以下命令有效:

alter table foo drop constraint un_foo drop index;

对于主键,类似命令 alter table foo drop primary key drop indexdocumentationOracle Developer Community discussion中 . 此外,this answer at AskTom也使用此语法(对于 keep index ) . 但是我没有在 alter table 命令的铁路图中看到这种语法的任何推理 .

问题:语法是 alter table foo drop constraint un_foo drop index 合法吗?如果是这样,基于铁路图中的文档或流程?如果没有,为什么命令不会失败?

谢谢!

1 回答

  • 1

    根据@ Chris Saxonmy equivalent question posted to AskTom的回答,语法被确认为有效但文档中没有 . 是否是文档错误或意外副作用的决定仍未得到解决 .

    我个人决定依赖语法,因为除其他事项外,我还建议在My Oracle Support中使用 .

    如果要求绝对安全(读取:符合文档),唯一的可能性是使用语句 alter table foo drop unique (name) drop index; .

    我在blogpost(捷克语)中总结了(不是那么实质性)关于这个问题的情况 .

相关问题