Hello! Please advise how you can store reviews on objects in the database? If all objects are divided into tables - parks, cafes, theaters, etc. and for each object of each group it is necessary to keep a review, a comment. I can’t think of an optimal solution.
- You can create a separate table for reviews (unique object identifier, review identifier, content, date) - AppLend
- @ Qwerty67888, create a table of groups, then create a table of objects, having started a review table, all this is connected by the primary key. - Smash
- > it is simply assumed that there will be a lot of facilities, it is necessary for the map of Penza, and perhaps there are hundreds of millions in Penza or billions of cafes / restaurants / theaters? I suppose not. Therefore, you can easily reduce all the objects into one table (there will be a few thousand of them maximum, and taking into account that this is just a graduation project, then perhaps not even thousands, but hundreds or tens. For any DBMS, this is nothing) DreamChild
- What then will be the primary key in such a table? - Qwerty67888
- > it is not clear to me what will be in the feedback table - which fields? create a table "object type" In it you will bring all possible types - a restaurant, cafe, theater, park and so on. Then a table of objects. It contains data on all your theater-parks with a foreign key on the table of types. Then a review table, in which you will store information about reviews with a foreign key on the object table. That's it - DreamChild
|
1 answer
You have tables like:
Имя таблицы Поля ------------------- Парки id, name, ... Рестораны id, name, ... ... id, name, ...
The easiest way in my opinion is to create a "Responses" table with id fields (ID ID), table_name (the name of the table in which the object to which the review relates), obj_id (object identifier in the table_name table, for which the feedback is stored) comment (text of the review).
To select all reviews for Restaurants with id = 23:
SELECT comment FROM Отзывы WHERE table_name = "Рестораны" AND obj_id = 23
- But it’s better, of course, to reduce everything into a single "Objects" table and add the "Object type" field, then in the Reviews table you will only have to store the object ID and no other fields are needed to assign a response to an object - MDJHD
|