Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need help with setting up a link table
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 12/22/2010 :  15:12:42  Show Profile  Reply with Quote

I am using sql server 2008 and created link tables for 1 to many and many to many. Example, patients can have many different stays in the hospital. So, I have a patients, hospitalstays, patientshospitalstays tables. Patients will have the PatientId primary key. HospitalStays wil have HosStayId as its primary key. The PatientsHospitalStays table will only PatientId and HosStayId columns. When I added the foreign relationship, it tells me to us unique contraints on the PatientId and HosStayId columns, but that will enforce uniqueness on those columns. The PatientId columns will contain multiple occurrance of the same PatientId value.

How do I resolve this?

Flowing Fount of Yak Knowledge

5155 Posts

Posted - 12/22/2010 :  15:40:27  Show Profile  Reply with Quote
You may not need a link table at all. Assuming this is a one to many (and not many to many relationship), you could add foreign key column in the hospitalstays table which references the patientId column from the patients table.

If a "hospital stay" is defined in such a way that many patients can share a single hospital stay, then you would need link tables etc. But, I can't visualize how that would be. (I cringe at the thought of more than one patient sharing even a single hospital room! :-))
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000