Should I create a table by category, or a single table?

Asked

Viewed 185 times

1

I want to set up a classified site and I have a question: how can I create the categories in the comic book? Create an ad table for each category? Or create a table Categorias with them inside? What’s the best way?

  • 1

    That question is a little broad, no?

  • 2

    Wide? I don’t see anything wide.. just wanted to know how I can do (the best way is by doing X or doing Y) this is broad?

  • 2

    Make a table for categories, with foreign key.

  • 2

    I think modeling and normalization is not a broad subject, it is not at all that there are tags for this.

  • 6

    DO NOT create a table for each category.

  • 2

    If the only thing that varies from one category to another is the name and unique identifier (ID), do not create more tables.

Show 1 more comment

1 answer

4

If category is a very closed concept, the ideal is nay create a table for each category.

A good sanity exercise: imagine that you already have a thousand news on the site, and now every news or category needs to have an extra column. You prefer to make changes - and still risk making mistakes - in just one table or twenty?

There are two ways to deal with categories, in your case:

  • A table of categories, and the news table has a foreign key to it. This brings two advantages: when changing the category name you update all its news automatically, and to add a new category just add a record in a table.

  • Category as a textual type column in the news table. This can be seen by many as denormalization. This simplifies the schema from the bank and, depending on how it is done, it can make searches faster. But to update a category, you need to update all the news records of that category.

If the category is to have more information than the name, I suggest you prefer the first form.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.