2012-12-02 13 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

相关问题