开发者

How should I go about making sure the value pairs in this table are unique?

开发者 https://www.devze.com 2022-12-16 18:50 出处:网络
I am using Visual Web Developer and Microsoft SQL server. I have a tag table \"Entry_Tag\" which is as follows:

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 ta开发者_运维技巧g_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?


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.


Create an UNIQUE INDEX to for entry_id and tag_id.

CREATE UNIQUE INDEX index_name ON table (entry_id, tag_id)
0

精彩评论

暂无评论...
验证码 换一张
取 消