2017-11-10 242 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(捷克語)中總結了這個問題的情況(不是很多)。