【发布时间】: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 位于documentation 或Oracle 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