2017-11-10 572 views
2

我的Oracle 11.2.0.2.0和通过下面的脚本创建唯一约束的表:Oracle alter table drop constraint索引语法上有效吗?

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开发者被备份,然后还原,则 un_foo唯一索引由 明确命令放置在 /**/线创建

这样一个显式创建的索引不会被上面的alter命令删除。我意识到下面的命令作品:

alter table foo drop constraint un_foo drop index; 

对于主键,类似命令​​处于documentationOracle Developer Community discussion。此外,this answer at AskTom也使用此语法(对于keep index)。然而我在alter table命令的铁路图中没有看到这种语法的推理。

问题:语法是alter table foo drop constraint un_foo drop index合法吗?如果是这样,根据什么文件或流量在铁路图中?如果没有,为什么命令不会失败?

谢谢!

回答

1

根据@Chris Saxonmy equivalent question posted to AskTom的回答,语法被确认为正在使用,但不存在于文档中。 无论是doc bug还是意外副作用,这个决定都还没有解决。

我个人决定依赖语法,因为在My Oracle Support中也建议使用这种语法。

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

我在blogpost(捷克语)中总结了这个问题的情况(不是很多)。