2016-02-12 102 views
4

我試圖創建一個新的表(tableB)與外鍵約束到另一個表(tableA),只是想知道我是否可以與此一起創建所需的所有約束和索引。我的目標是有一個create table聲明,事後不需要alter table…聲明,也沒有其他create index…聲明。這可能嗎?感謝提前任何提示:)如何在一個create table語句中使用Index創建外鍵? (甲骨文)

create table tableA 
(
    id number 
, constraint tableApk primary key (id) 
); 

create table tableB 
(
    id number 
, constraint tableBfk foreign key (id) references tableA (id) 
         on delete cascade 
         using index (
         create index tableBfkidx on tableB (id) 
         ) 
); 
+0

這完全是關於'tableB',而不是'tableA' ......並且對於主鍵我可以使用'使用索引(...)' - 只是想知道爲什麼這對外鍵是不可能的。 – Ben

回答

6

這是不允許的。 Per the documentation a using_index_clause只能指定爲唯一約束或主約束。

祝你好運。

+0

我錯誤地想使用'使用索引(...)'作爲我的外鍵的主鍵以及...也許在文檔中忽略了這個註釋。謝謝! – Ben