2012-12-02 14 views
0

我有兩個表,表A和B表如果外鍵表列與Oracle + yii框架中引用的父表列不匹配,該怎麼辦?

現在表A有A.id和B具有B.id因此B.id是外鍵與A.id

現在我的問題是鏈接,A具有A.extraid B「中有許多行,其中列名是B.notsamextraid。換句話說,B.notsamextraid的值匹配A.extraid

的值應該怎麼做才能讓Yii匹配這兩列中他們都有不同名稱的列?

(我不是授權改變B.notsamextraid的名字變成B.extraid)

回答

1

的Yii的文件說DO define foreign-key relationships in the database schema

你可以試試下列表格嗎?警予應該能夠拿起兩個外鍵:

create table a (
    id  int not null primary key, 
    extraid int not null unique 
); 

create table b (
    id   references a(id), 
    notsamextraid references a(extraid) 
); 

編輯:要找出是否已經有兩個表之間的外鍵,你可以使用下面的查詢。這不是在這個星球上最漂亮的查詢,但隨後有複製和粘貼:-)

select t1.owner, t1.constraint_name, t1.constraint_type, t1.table_name, c1.column_name, 
     t2.owner, t2.constraint_name, t2.constraint_type, t2.table_name, c2.column_name 
    from all_constraints t1 
    join all_cons_columns c1 
    on t1.constraint_name=c1.constraint_name 
    and t1.owner=c1.owner 
    and t1.table_name=c1.table_name 
    join all_constraints t2 
    on t1.owner=t2.owner 
    and t1.r_constraint_name=t2.constraint_name 
    join all_cons_columns c2 
    on t2.constraint_name=c2.constraint_name 
    and t2.owner=c2.owner 
    and t2.table_name=c2.table_name 
    and c1.position=c2.position 
where t1.constraint_type = 'R' 
    and t1.table_name in ('A','B'); 
+0

我沒有權限改變表......我用的方式....在Yii框架中解決這個問題的一種方法? – sasori

+0

如果表b和a之間有兩個外鍵約束,你可以問問設置表的人嗎? –

+0

我可以問明天,但是沒有任何oracle命令可以用來在sql開發人員中運行,以瞭解是否有兩個關鍵約束條件? – sasori

相關問題