I've got the following tables defined:

```
- Group
  - GroupID (pk - int)
  - ...

- Item
  - ItemID (pk - int)
  - ...

- Groups_Items
  - GroupID (pk - int)
  - ItemID (pk - int)

```

There is a FK on the GroupID linked to the Group table and there is one on the ItemID which is linked to the Item table.

I need to add an optional relationship to the Groups\_Items table i.e. RuleSetId

```
- Groups_Items
  - GroupId (pk - int)
  - ItemId (pk - int)
  - RuleSetId (int - nullable)

```

With the Ruleset table defined as follows:

```
- RuleSet
  - RuleSetId (int)
  - RuleId (int)

```

and the Rule table is defined as follows:

```
- Rule
  - RuleId (int)
  - ...

```

When I try to add an FK using the RuleSetId from the RuleSet table to the RuleSetId from the Groups\_Items table, it's giving me an error telling me I'm not allowed.

Each Item must be associated to a group, and a group can have multiple items but I want to provide the option to allow one or more rules to be associated to an item via a RuleSet. Note that I don't want to associate the ruleset directly to the item itself but to the item associated to the group as the item could be the same but associated to different groups and a different set of rules may apply depending on the group the item belongs to.

I hope this makes sense.

I'm struggling to get this to work so I must be designing this incorrectly but I'm not sure how best to approach this.

**Update - 1**

Here's the diagram of what I'm trying to achieve. Note that I've added the RuleSet table in the meantime which just contains a primary key i.e. RuleSetId

[![enter image description here](https://i.stack.imgur.com/mv0zK.png)](https://i.stack.imgur.com/mv0zK.png)

I'm getting the following error when I try to add a relationship between the GroupsItems table and the RuleSet table:

```
The ALTER TABLE statement conflicted with the FOREIGN KEY constraint 
"FK_GroupsItems.ERuleSet". The conflict occurred in database 
"MyDatabase", table "dbo.RuleSet", column 'RuleSetId'.

```

and I'm getting the following error when I try to add a relationship between the RuleSet table and the RuleSetRules table:

```
Unable to create relationship 'FK_RuleSetsRules.RuleSet'.
The ALTER TABLE statement conflicted with the FOREIGN KEY constraint 
"FK_RuleSetsRules.RuleSet". The conflict occurred in database "MyDatabase", 
table "dbo.RuleSet", column 'RuleSetId.

```