sqlserver中表之间的关系 [英] Relationships between tables in sqlserver

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

问题描述



我不知道如何在表之间建立关系(外键),请给出步骤

Hi,

i have no idea on how make relationships(Forign key) between tables please give steps

推荐答案

请遵循以下步骤:-

1.在表设计器中创建外键关系

2.在对象资源管理器"中,右键单击将在关系的外键侧的表,然后单击设计".

3.表格在表格设计器中打开.

4.从表设计器"菜单中,单击关系".

5.在外键关系"对话框中,单击添加".

6.该关系以系统提供的名称显示在选定的关系"列表中,格式为FK_< tablename> _< tablename> ;,其中tablename是外键表的名称.
7.在选定的关系"列表中单击该关系.

8.单击右侧网格中的表和列规格",然后单击属性右侧的省略号(…).

9.在表和列"对话框的主键"下拉列表中,选择将位于关系的主键侧的表.

10.在下面的网格中,选择构成表主键的列.在每列左侧的相邻网格单元格中,选择外键表的相应外键列.

11.表设计器建议关系的名称.要更改此名称,请编辑关系名称"文本框的内容.

12.选择确定"创建关系.


**注意:-您为外键选择的列必须具有与其对应的主列相同的数据类型.每个键中的列数必须相等.例如,如果关系的主要方面的表的主键由两列组成,则需要将每个这些列与该关系的外键方面的表中的列进行匹配. />


请参考这些链接以获取更多详细信息:-

http://www.youtube.com/watch?v=xL7h4VQhXFY [如何建立外键关系?

Follow the steps:-

1. To create a foreign key relationship in Table Designer

2. In Object Explorer, right-click the table that will be on the foreign-key side of the relationship and click Design.

3. The table opens in Table Designer.

4. From the Table Designer menu, click Relationships.

5. In the Foreign-key Relationships dialog box, click Add.

6. The relationship appears in the Selected Relationship list with a system-provided name in the format FK_<tablename>_<tablename>, where tablename is the name of the foreign key table.

7. Click the relationship in the Selected Relationship list.

8. Click Tables and Columns Specification in the grid to the right and click the ellipses (…) to the right of the property.

9. In the Tables and Columns dialog box, in the Primary Key drop-down list, choose the table that will be on the primary-key side of the relationship.

10. In the grid beneath, choose the columns contributing to the table''s primary key. In the adjacent grid cell to the left of each column, choose the corresponding foreign-key column of the foreign-key table.

11. Table Designer suggests a name for the relationship. To change this name, edit the contents of the Relationship Name text box.

12. Choose OK to create the relationship.


**Note:-The columns you choose for the foreign key must have the same data type of the primary columns they correspond to. There must be an equal number of columns in each of the keys. For example, if the primary key of the table on the primary side of the relationship is made up of two columns, you will need to match each of those columns with a column in the table for the foreign key side of the relationship.


Please refer these links for more details:-

http://www.youtube.com/watch?v=xL7h4VQhXFY[^]

how to make foreign key relationship?

creating-primary-key-foreign-key-and-default-constraint/

I hope this will help you out.

Thanks


检查这些链接

msdn.microsoft.com [ stackoverflow. com [
Check these links

msdn.microsoft.com[^]

stackoverflow.com[^]


您知道MSDN还是Google?

看看此
创建和修改外键约束 [ ^ ]

问候
米歇尔
You know MSDN or Google?

Have a look at this Creating and Modifying FOREIGN KEY Constraints[^]

regards
Michel


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

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