复合外键约束通过PhpMyAdmin? [英] Composite Foreign Key Constraint via PhpMyAdmin?

查看:197
本文介绍了复合外键约束通过PhpMyAdmin?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过PhpMyAdmin接口将一个复合(多列)外键添加到InnoDB表中?我已经在目标表中有合适的复合主键,并且我可以单列外键约束,但是我无法在界面中找到合成主键。

 表格记录
- 日期
- 服务
PRIMARY KEY(日期,服务)

表格发行
- Issue_Id
- Log_Date
- Log_Service
PRIMARY KEY Issue_Id
FOREIGN KEY(Log_Date = Log.Date,Log_Service = Log.Service)

除了外键之外,我进入PhpMyAdmin关系视图,我只能看到如何设置一个FK对Log.Date,而不是对Log.Service根本。

解决方案

我刚刚遇到了一个类似的问题,在phpMyAdmin中设置了一个复合外键,也许我的解决方案也可以帮助你。



这里是我的设置:



正如你所看到的,我的ConferenceRoom表中有一个复合主键,其中的一部分也是一个外键在表Office中的 streetaddress (这可能与您的问题有所不同)。



这个组合主键是被引用的通过表InstPicture中的复合外键,但我的问题是,尽管已经定义为主键索引,phpMyAdmin只会引用会议室中的名称列主键,而不是 office_streetaddress 列。



我在这里错过的是我没有设置ConferenceRoom和Office 之间的关系试图建立ConferenceRoom和InstPicture之间的关系。我猜我忘了先处理强有力的问题,正如数据库方法论所要求的那样。

在ConferenceRoom和Office之间定义关系时, office_streetaddress 列出现在索引列表中并且可以被表InstPicture中的 conferenceroom_office_streetaddress 列引用。



我希望这可以帮助你,也许尝试为你的Log.Service列创建一个单独的索引。或者如果这是一个FK,建立它的关系,然后再试一次。


Is there a way to add a composite (multi-column) foreign key to an InnoDB table via the PhpMyAdmin interface? I already have the appropriate composite primary key in the target table, and I can single column foreign key constraints, but I can't find a way in the interface to do the composite one.

Table Log
- Date
- Service
PRIMARY KEY (Date,Service)

Table Issue
- Issue_Id
- Log_Date
- Log_Service
PRIMARY KEY Issue_Id
FOREIGN KEY (Log_Date=Log.Date,Log_Service=Log.Service)

Everything is already set up except the foreign key; I go into the PhpMyAdmin relation view and I can only see how to set up a FK against Log.Date and not against Log.Service at all.

解决方案

I just ran into a similiar problem setting up a composite foreign key in phpMyAdmin and maybe my solution could help you as well.

Here's my setup:

As you can see I have a composite primary key in my ConferenceRoom table, part of which is also a foreign key to streetaddress in table Office (this might differ from your problem).

This composite primary key is to be referenced by a composite foreign key in table InstPicture but the problem for me was that, in spite of having defined both as primary key indexes, phpMyAdmin would only reference the name column in the ConferenceRoom primary key, and not the office_streetaddress column.

What I was missing here was that I had not set up the relation between ConferenceRoom and Office before trying to set up the one between ConferenceRoom and InstPicture. I guess I forgot to handle the strong enities first, as database methodology dictates.

When the relation had been defined between ConferenceRoom and Office, the office_streetaddress column showed up in the list of indexed columns and could the be referenced by the conferenceroom_office_streetaddress column in table InstPicture.

I hope this could help you as well, maybe try creating a separate index for your Log.Service column. Or if that is a FK, set up its relations and then try again.

这篇关于复合外键约束通过PhpMyAdmin?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆