0

For my RSS aggregator, there a four tables that represent rss and atom feeds and, their articles. Each feed type and entry type will have zero or more categories. In the interest of not duplicating data, I'd like to have only one table for categories.

How can I accomplish this?

enter image description here

user465001
  • 806
  • 13
  • 29

1 Answers1

1

One way is to keep categories in one single table - e.g. category - and define an X table for each entity/table that needs 0 or more category associations:

rssFeedXCategory

rssFeedId INT FK -> rssFeed (id)
categoryId INT FK -> category (id)

atomFeedXCategory

atomFeedId INT FK -> atomFeed (id)
categoryId INT FK -> category (id)    

and so on.

You can define a PK for both columns in each table, but an extra identity column may also be used. When working with an ORM, I also have an extra identity/autoincrement column (e.g. XId INT), so that a single column can be used to identity a row.

Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
  • Ok. This makes sense. I'll try it out now. I'm using an ORM as well. Can you give me an example of how an extra identity helps? – user465001 May 01 '16 at 20:13
  • 1
    It might help when trying to update a PK column value (e.g. move an item from a category to another), as this might be forbidden in some ORMs (see [here](http://stackoverflow.com/questions/29675081/how-to-update-primary-key-from-entity-framework) ). Generally, the identity column is not required, as pointed out [here](http://stackoverflow.com/questions/2667988/why-single-primary-key-is-better-than-composite-keys). – Alexei - check Codidact May 01 '16 at 21:25
  • Thanks for you help, Alexei! – user465001 May 01 '16 at 21:31