There is a table of cities in my database. There is a table of clients and a table of forecasts for each city. Every client has a list of cities for which they require forecasts. I need to put these lists in the database for they are in text files now.
I can think of 2 ways to accomplish that:
Data will be processed with PHP. DB is small : total of 50 clients and 200 cities.
What I don't like about the first approach is that anytime I have a new client, I need to change the table structure.
I tend to like the second approach more but somehow it doesn't fit into the "DB way" of structuring data.
What do you think?
I don't know mariadb, but you are trying to model a many-to-many relationship.in an SQL database you would create a new table "subscriptions" (or w/e you call it) like this:
user_id | city_id | (additional options if needed)
However in mongodb you would instead (usually) have a list of references (ids):
collection users:
{
"name": "blabal",
"cities": [ 1, 2, 7 ]
}
Never do that string variant, it wastes quite a lot of space and is inefficient to search for etc.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.