Answer the question
In order to leave comments, you need to log in
Problem with understanding database design, help?
I have a large table, let's call it "ads". You need to assign several "tags" to one "advertisement".
Here's my line of thinking:
Create a separate "tags" table and list the primary keys in the "tags" column of the first table. But enumeration violates 1NF.
Create a many-to-many "declarations-tags" table, but there will be a lot of values after each "declaration" insertion.
You can list tags simply as a string in a field.
How is it done in real projects?
Answer the question
In order to leave comments, you need to log in
for example, one ad has an average of 3 tags, for 1 million ads there will be 3 million entries in "tag ads", how will it be in terms of speed when sampling? Will I benefit greatly if I break the rule and write tags by listing them in a comma-separated string?
Will I benefit greatly if I break the rule and write tags by listing them in a comma-separated string?
._________. .______________. .____________.
| post | | post_tag | | tag |
|=========| |==============| |============|
| id: int |<------------| post_id: int | | id: int |
| ... | | tag_id: int |---------->| name: text |
|_________| |______________| |____________|
I'm not a database expert at all, but I can create a separate table for tags ... list them there,
then add a field / fields to the declaration and mark it there already. like 1 there is a tag, 0 there is no tag... and so on for each
Using a separate table for tags is the correct solution.
But not everything is so clear. Using a list is also possible and has its advantages. For example, a separate table is used on Habré and there is no way to add your own clarifying tag for a question. On other web2, you can add your own to the list. Regarding the fear of deleting and renaming: has a tag ever been deleted on Habré? How long ago was it renamed?
The use of lists is supported by many DBMS, and some have a special data type.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question