有关SQL Server中表关系的问题 [英] Problem on relation of tables in sql server

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

问题描述

嗨 我正在开发一个sql数据库,但是我遇到了表关系方面的问题.假设我们有一个名为"TASK"的表,其中包含以下字段:id,TaskName,Type,startDate,endDate.每个任务具有不同的属性和详细信息.因此,我必须为每种任务类型创建一个表,并将Task连接到这些表.

我的问题是如何将任务"连接到其他表?

如果您知道更好的方法.

请帮帮我.

感谢您的回答.

解决方案

您需要在Task表中实现外键约束.

看一下此页面 [
TaskType至少应包含TaskTypeID和TaskTypeDescription列.
TaskTypeID应该是主键NOT NULL.它应该是Integer数据类型列,并且您可以根据需要将其设置为Identity列.
将任务"表中的类型"列更改为Integer数据类型.

然后按照链接中显示的模式进行操作.


您可以为属性创建一个表,并将所有属性存储在给定任务的单个表中.


<您需要创建一个用于存储任务的表和一个用于存储不同类型任务的表.在taks表(第1个表)中,设置特定任务类型(第2个表)的行ID.

有关关系的教程:

http://www.functionx.com/sql/Lesson11.htm [
My question is how can I connect "Task" to other tables?

If you know a better way.

Please help me.

Thanks for your answers.

You need to implement a foreign key constraint in your Task table.

Take a look at
this page[^] from MSDN and also follow the links on the page. In the diagram The ''SalesOrderHeader'' would be your Task table and the ''SalesPerson'' would be the new table you should create for TaskType.

TaskType should contain at least TaskTypeID and TaskTypeDescription columns.
TaskTypeID should be the Primary Key NOT NULL. It should be an Integer datatype column and you can make it an Identity column if you wish.
Change the Type column in your Task table to be an Integer datatype.

Then follow the pattern shown in the link.


You can create one table for attributes and store all the attributes in the single table for a given task.


you need to create a table where you store tasks and a table where you store different types of tasks. In the taks table (1st) you set the ID of row of the specific tasktype (2nd table)

For a tutorial about relationships:

http://www.functionx.com/sql/Lesson11.htm[^]


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

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