SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

c0micrage
Starting Member

USA
1 Posts

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

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?

sunitabeck
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  
 New 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.08 seconds. Powered By: Snitz Forums 2000