【问题标题】:Is Oracle alter table drop constraint drop index syntactically valid?Oracle alter table drop constraint drop index 在语法上是否有效?
【发布时间】:2018-04-24 05:53:45
【问题描述】:

我有 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 唯一索引是由 explicit 命令创建的,放在/**/ 行:

    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 index 位于documentationOracle Developer Community discussion 中。此外,this answer at AskTom 也使用这种语法(对于keep index)。但是我在alter table 命令的铁路图中没有看到这种语法的任何理由。

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

谢谢!

【问题讨论】:

    标签: oracle syntax oracle11g alter-table


    【解决方案1】:

    根据@Chris Saxonmy equivalent question posted to AskTom 的回答,该语法已确认有效,但未出现在文档中。 是文档错误还是意外副作用的决定仍未解决。

    我个人决定依赖语法,因为除其他外,My Oracle Support 也建议使用它。

    如果需要绝对安全(阅读:符合文档),唯一的可能是使用声明alter table foo drop unique (name) drop index;

    我在blogpost(捷克语)中总结了(不是那么重要)有关此问题的情况。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多