关系数据库问题 [英] Relational database question

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

问题描述

我有一个特定但简单的问题。我的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.

推荐答案

根据您的描述,至少有三个实体,第一个根据用户要求明确说明这些实体的内容,例如:

1.什么是公司,目的和数据属性?

2.什么是联系人,其目的和数据属性?

3.什么是代表,目的和数据属性?

4.他们之间的关系是什么,如果有的话?

使用图表来表示第1点到第4点。

使用它作为参考数据库设计简介 [ ^ ]
Based on your description, there are at least three entities, first state clearly the what's of these entities based on the user requirements, e.g.:
1. What is a company, its purpose, and its data attributes?
2. What is a contact, its purpose, and its data attributes?
3. What is a rep, its purpose, and its data attributes?
4. What is the relationships between them, if any?
Use a diagram to represent points 1 to 4.
Use this as reference Introduction to database design[^]


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

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