views:

36

answers:

2

I am using Visual Web Developer and Microsoft SQL server. I have a tag table "Entry_Tag" which is as follows:

entry_id tag_id

I want to make the entry_id and tag_id pairing unique. A particular tag can only be applied to an entry once in the table. I made the two columns a primary key. They are also both foreign keys referencing the ids in their respective tables. When I dragged the tables into the Object Relationship Designer it only showed a relationship line between either "Entry_Tag" and "Entry" or when I tried again between "Entry_tag" and "Tag".

The "Entry_tag" table should have a relationship with both "Tag" and "Entry".

How do I go about doing this?

+4  A: 

In general, you can add a unique constraint on the table that includes both columns. In this case, including both of the columns in the primary key should have already done this. If you have relationships set up for each field to other tables, then I believe those relationships should be displayed in the query designer... I see no cause for this given the information you've provided - perhaps you need to post more information.

Michael Bray
Thanks. I was making the mistake in overwriting the relation I had set instead of clicking "add"..
GreenRails
+1  A: 

Create an UNIQUE INDEX to for entry_id and tag_id.

CREATE UNIQUE INDEX index_name ON table (entry_id, tag_id)
Yada
Since both fields are in his primary key this would be excessive.
JoshBerke