在一个外键和三个主键之间创建一对多关系 [英] Create One to many Relation , between one Foriegn Key and Three Primary Key

查看:100
本文介绍了在一个外键和三个主键之间创建一对多关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有四个桌子
(1)表1具有FK(F1)
(2)表2具有PK(F2)
(3)表2具有PK(F3)
(4)表2具有PK(F4)
我想在Table1,Table2,Table3和Table4之间建立三个关系
如上所述,表1具有FK,其他3个具有主键
我做到了,但是当我尝试向表1输入数据时,它不会仅看到表1和表2之间的关系
我只是想在表1的FK中添加一个ID,该ID必须在表2或表3或表4主键中

任何人都可以帮助我做到这一点

谢谢Advanced

I have Four Tables
(1) Table1 has FK (F1)
(2) Table2 has PK (F2)
(3) Table2 has PK (F3)
(4) Table2 has PK (F4)
i Want to Make Three Relations between Table1,Table2,Table3 and Table4
As described above Table1 has the FK and the 3 others have the Primary Keys
i did that but when i try to enter data to Table1 it does not see only the Relation between Table1 and Table 2
Simply i Want To Add in the FK of Table1 an ID that must be in Table2 or Table3 or Table4 Primary Key

any one can help me in doing that

thanks in advanced

推荐答案

这难道不是不可能的吗?

请参阅以下有关外键的说明: http://en.wikipedia.org/wiki/Foreign_key [ ^ ].

特别要注意代码示例.查找:对于名为TABLE_NAME的表,总是与其他名为other_table的表相关联地定义外键.想一想:为什么会这样呢?否则,您将不会获得有关外键值指的信息.键(主键)只能在单个表的范围内唯一.如果您具有某个外键的值,则没有外键的名称将无法确定该表,而外键的名称在使用此键的表的范围内是唯一的.此信息显示在数据库模式中.这样便可以通过表的众多在表之间建立一对一,一对多和多对多的关系. i>主键和外键之间的一对一关系.

实际上,在最简单的情况下,您需要在Table1中创建三个外键以与其他三个表建立关系.

—SA
Isn''t this obvious that this is impossible and makes no sense?

Please see this explanations of the foreign key: http://en.wikipedia.org/wiki/Foreign_key[^].

In particular, pay attention for the code samples. Look: for a table named TABLE_NAME, a foreign key is always defined in association with some other table named other_table. Think a bit: why is that so? Otherwise, you would not have information on what a value of a foreign key is referring to. The keys (primary) can be only made unique in the scope of a single table. If you have a value of some foreign key, you would not be able to determine the table without the name of a foreign key which is unique in the scope of the table using this key. This information presents in the database schema. This is how it''s possible to establish one-to-one, one-to-many and many-to-many relations between tables: through the multitude of one-to-one relations between primary and foreign keys.

In practical terms, in a simplest case, you need to create three foreign keys in Table1 to establish relations with three other tables.

—SA


这篇关于在一个外键和三个主键之间创建一对多关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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