Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted

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:
SQL
SELECT a.EmpID, a.EmpName, b.Address 
FROM Employees a
JOIN Addresses b
ON a.HomeAddress = b.AddrId
 
Share this answer
 
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 :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900