When does mysql need to create an associated table?

when does mysql need to create an associated table?
Center

such as

whether it is appropriate for mysql to use an associated table or to put associated fields in the table, the current design is as follows:
1. Article classification table cate
2. Article table article
3. Tag table tag
article table, in which cate_id,tag_id is used to associate two tables
there is also a way to write:
1. Article classification table cate
2. Article table article
3. Tag table tag
4. Article and article classification association table
4. Which of the two writing methods is more optimized, the article or the tag association table
? Thank you
for changing how to build an index.
Apr.25,2022

actually depends on the business scenario. Take the example of the article (assuming the design of the article table is reasonable)

if cate_id and tag_id of each article are unique, then both methods have their own advantages

  1. the advantage of using associated tables is to reduce the amount of data in the single table of the article, which is easy to expand, but the disadvantage is that it needs to connect one more table
  2. cate_id and tag_id the advantages of writing in article tables reduce the number of queries or joined tables, while the disadvantage is that the amount of data increases ( tag_id and cate_id indexes, field data), and is not conducive to expansion

if cate_id and tag_id of each article are not unique, you can only store data in a way similar to tag_id1,tag_id2 , which not only violates the first paradigm of database design, but also is extremely difficult to check articles through tag_id .

therefore, if it is an one-to-one relationship, it is more convenient to use an association table to look at the business. If it is an one-to-many relationship (such as multiple tags in an article) or many-to-many, it is more convenient to use an association table

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9873d-16de.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9873d-16de.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?