D
D
danforth2017-10-21 04:17:22
Database design
danforth, 2017-10-21 04:17:22

What is the best way to design comments in a database with many entities?

I don’t have much experience in database design, I tried to peep into popular engines, but I didn’t come to any single conclusion.
Task: there are many entities, it is necessary to make comments possible for each of such entities. For simplicity, let's take a car that has:
brand - id, name // e.g. Porsche
model - id, brand_id, name // e.g. 911
spec - id, model_id, name // e.g. Turbo S
engine - id, spec_id, hp, torque // engine for a specific specification
Option 1:
For each entity, create a separate table with the _comments suffix, thereby obtaining brand_comments, model_comments, etc., and bind to the primary key of each table.
Option 2:
We create a single comments table with the entity_code (varchar) attribute, where brand, model, spec, etc. will be stored, and already in the application itself we connect the desired model and make a request.
Option 3:
Not the best option, but nevertheless: make a separate comments table, where the page URL is the commented entity, i.e. if the page address is /cars/porsche/ then all comments will be linked to such an entity. The option is not very good. in case of changing the application routing, you can lose the connection of the page with the comments, this situation must be monitored clearly, it will not be possible to assign integrity to the DBMS. However, according to this scheme, as far as I know, Disqus works.
Which of these options is the best? Are there alternatives? If possible, describe in more detail the pros and cons of each option, so that it is clear why it should be abandoned, and remembered for the future.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Skorzhinsky, 2017-10-21
@AndyKorg

There are "two ways" (c):
1 Use the standard commenting tools in the database
2 Look at how this business is implemented in other databases, for example, in MS SQL

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question