MS SQL Bridge Table Constraints

Posted by greg on Stack Overflow See other posts from Stack Overflow or by greg
Published on 2010-03-11T19:23:24Z Indexed on 2010/03/11 19:29 UTC
Read the original article Hit count: 535

Greetings -

I have a table of Articles and a table of Categories.

An Article can be used in many Categories, so I have created a table of ArticleCategories like this:

  • BridgeID int (PK)

  • ArticleID int

  • CategoryID int

Now, I want to create constraints/relationships such that the ArticleID-CategoryID combinations are unique AND that the IDs must exist in the respective primary key tables (Articles and Categories).

I have tried using both VS2008 Server Explorer and Enterprise Manager (SQL-2005) to create the FK relationships, but the results always prevent Duplicate ArticleIDs in the bridge table, even though the CategoryID is different.

I am pretty sure I am doing something obviously wrong, but I appear to have a mental block at this point.

Can anyone tell me please how should this be done?

Greaty appreciated!

© Stack Overflow or respective owner

Related posts about sql-server-2005

Related posts about constraints