Can you please tell how it is more reasonable to store comments in the database? This situation: you need to implement commenting in the "blog" and in the "Photo Album". Here are my thoughts, or make one table with fields

id-ΠΊΠ»ΡŽΡ‡ text-тСкст ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π° page_id-id страницы Π½Π° ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΉ сам ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚ name-имя ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ type-Ρ‚ΠΈΠΏ, "Π‘Π»ΠΎΠ³", Π»ΠΈΠ±ΠΎ "Π€ΠΎΡ‚ΠΎΠ°Π»ΡŒΠ±ΠΎΠΌ" 

Or create two tables without the field "type" - one in the photo, the other on the blog. How will be more correct? I would like to hear the advice of professionals, but then suddenly something else will come to my mind to comment out ... every time to create a table? Or the first option will do, and immediately a tip, how to get these comments so that the speed does not leave much to be desired, maybe there is a thread

 SELECT 

Which can pass several parameters at once

 WHERE 

    2 answers 2

    There is no unambiguous solution. You can keep one table for all comments, you can keep your own for each type.

    The decision is up to you.

    • If comments are considered as a separate entity, i.e., for example, there is a search by comments (regardless of what content they have been added to), it is more convenient, of course, that this is one table. Here we must take care of the indexes. The use of several tables does not contradict the possibility of searching by the union from the selects.
    • If the parent structures are separate (on the blog and photo album their tables), it is logical to separate and comments. And the combined table does not contradict this logic; separation by type will have the same effect.

    Threat Of course, if we are not talking about a giant database with billions of comments. There, the approach is not in terms of "what will happen if I want to comment on something else," but "how to ensure speed" and "how would I partition the data" ...

    • Thank you for the clarification! I chose the first option, because I think more than 1k messages will not be - Sexy Girl

    I would do with type. And you can display it like this:

     SELECT * FROM `comments` WHERE `type` = 'blog' AND `page_id` = '1'