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

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 Complex Relationship quandry

Author  Topic 

jimsurf
Starting Member

18 Posts

Posted - 2010-01-12 : 22:47:04
I have a db with 3 tables. User, Company, Role
Each User can be associated with one to many Companies. (Create User_Company Table, that has UserId and CompanyId in it, to manage the relationship)
Each Role is associated with one, and only one Company. (Roles are company Specific) (Role Table has CompanyId as FK, no Role_Company table is needed to manage relationship)
Each User can have one, and only one role per company

How do I create a relationship between a role (which is associated with a single company), and a user? The User must be associated with the same company in User_Company as the companyID in the role table.

I don't see any way to create a constraint that the companyId in the User_Company table is the same as the companyId in the Role Table

   

- Advertisement -