将一个表链接到许多其他表中的一个表 [英] linking one table to one of many other tables
本文介绍了将一个表链接到许多其他表中的一个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个地址表,可以在许多其他表中引用(员工表,大学表,Work_Experience表,......其他表)
链接地址表的最佳做法是什么知道地址行只能用于一个表的其他表。
I have an Address table which can be referenced in many other tables (Employee table, University table, Work_Experience table , ... other tables )
what is the best practice to link address table with the other tables knowing that an address row will be only for one table.
推荐答案
在地址表中使用ID行(INT或UNIQUEIDENTFIER很好)并设置作为其他表格中的外键。
然后,当您想获得员工的地址时,您只需使用加入:
Use an ID row in the address table (INT or UNIQUEIDENTFIER is fine) and set that as a FOREIGN KEY in the other tables.
Then when you want to get the address for an employee, you just use a join:
SELECT a.EmpID, a.EmpName, b.Address
FROM Employees a
JOIN Addresses b
ON a.HomeAddress = b.AddrId
您可以参考Microsoft提供的AdventuresWorks示例数据库。
AdventureWorks中的模式 [ ^ ]
查看 地址 [ ^ ]表
只是一个主键 - 地址表和从属表之间的外键关系应该足够了。
希望,它有帮助:)
You can take reference of AdventuresWorks sample DB provided by Microsoft.
Schemas in AdventureWorks[^]
Take a look at the Address[^] table
Just a Primary Key - Foreign Key relation between Address and dependent tables should be enough.
Hope, it helps :)
这篇关于将一个表链接到许多其他表中的一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文