本文介绍了关系数据库问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个特定但简单的问题。我的SQL数据库中有三个表。我想在第一个中使用主键作为另外两个中的外键。现在,这是我遇到问题的地方。



我已经完成了所有三个表没有问题。基本上我有companyData,contactData和repData。我很确定这是一对多的关系。每家公司都可以有联系人和多个销售代表。代表和联系人只能有一家公司。



我的问题是......即使我将表与相同的主键绑在一起,是否有某种方法从数据库中提取数据或它会自动将代表的ID与公司ID相关联吗?



我的尝试:



只需在数据库中创建表并创建外键。

I have a specific, yet simple question. I have three tables in my SQL database. I want to use the primary key in the first one as the foreign key in the other two. Now, this is where I run into problems.

I have made all three tables with no problem. Basically I have companyData, contactData and repData. I'm pretty sure it's a one to many relation. Every company can have a contact and multiple reps. A rep and contact can have only one company.

My question is... even if I tie to tables together with a 'same' primary key, is there a certain way to pull the data from the database or will it just automatically associate the rep's ID with the company ID?

What I have tried:

Just creating the tables in the database and making the foreign keys.

推荐答案


这篇关于关系数据库问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 22:31