I am using SQL Server Management Studio connected to SQL Server 2008 R2.
- I have a table called
Userwith a columnId(uniqueidentifier) - I have a table called
Rolewith a columnId(uniqueidentifier) - I want a table called
UserRolePairwith 2 columns:UserIdandRoleId.
I need each row to be unique (no duplicate roles for each user).
This is easy – I just right-click, choose Indexes & Keys and create a new unique key, that is comprised of both columns.
Now what I need to do – is to create a foreign key from UserId to the Id column of the User table, and create a foreign key from RoleId to the Id column of the Role table.
But when I choose Relationships from the sub-menu – I get this:

First of all – why do I have 2 relationships here ??
Second of all – when I want to create a new foreign key now for each column separately I get this:

I can’t choose to RoleId the Id column of the Role table !
It says I need to assign both columns of UserRole table with foreign keys from the same table.
What is the solution ?
Is the ‘unique’ what’s causing my problems ?
Your best bet is to use T-SQL statements instead of struggling with the visual designers.
a) create foreign key from
UserRolePairtoRole:b) create foreign key from
UserRolePairtoUser:Just execute those in a query window (make sure to be in the right database!) and you’re done!