0

I've created a table called comments, comments has a property called ItemId which is used as the foreign key for two other tables posts and apps.

This is because i was hoping for the comments table to serve both the apps and posts table. However when trying to insert a value into the comments table it throws a foreign key constraint error.

Does anyone know the best way of accomplishing what I'm trying to do with the least amount of duplication?

Shannon
  • 843
  • 6
  • 22
  • It's not the error I need solving I know what is causing that it's the design I'm worried about. – Shannon Jun 14 '11 at 11:33

1 Answers1

1

See this question/answer.

Community
  • 1
  • 1
Damir Sudarevic
  • 21,891
  • 3
  • 47
  • 71
  • Thanks, should i flag this as a duplicate then? – Shannon Jun 14 '11 at 13:16
  • If you follow the posted answer (a case of the Gen-Spec pattern), you'll never have duplicates, because your posts and apps will not each have an autonumber PK of their own. Instead, their PK will be an FK to the superentity table. Comments reference one and only one row in the superentity table. – Walter Mitty Jun 14 '11 at 13:34