<tfoot id='tg5Xb'></tfoot>
<i id='tg5Xb'><tr id='tg5Xb'><dt id='tg5Xb'><q id='tg5Xb'><span id='tg5Xb'><b id='tg5Xb'><form id='tg5Xb'><ins id='tg5Xb'></ins><ul id='tg5Xb'></ul><sub id='tg5Xb'></sub></form><legend id='tg5Xb'></legend><bdo id='tg5Xb'><pre id='tg5Xb'><center id='tg5Xb'></center></pre></bdo></b><th id='tg5Xb'></th></span></q></dt></tr></i><div id='tg5Xb'><tfoot id='tg5Xb'></tfoot><dl id='tg5Xb'><fieldset id='tg5Xb'></fieldset></dl></div>
        • <bdo id='tg5Xb'></bdo><ul id='tg5Xb'></ul>
        <legend id='tg5Xb'><style id='tg5Xb'><dir id='tg5Xb'><q id='tg5Xb'></q></dir></style></legend>

        <small id='tg5Xb'></small><noframes id='tg5Xb'>

        在 MySQL 中存储多对多关系的最佳方式?

        时间:2024-04-16
        <i id='OOqEv'><tr id='OOqEv'><dt id='OOqEv'><q id='OOqEv'><span id='OOqEv'><b id='OOqEv'><form id='OOqEv'><ins id='OOqEv'></ins><ul id='OOqEv'></ul><sub id='OOqEv'></sub></form><legend id='OOqEv'></legend><bdo id='OOqEv'><pre id='OOqEv'><center id='OOqEv'></center></pre></bdo></b><th id='OOqEv'></th></span></q></dt></tr></i><div id='OOqEv'><tfoot id='OOqEv'></tfoot><dl id='OOqEv'><fieldset id='OOqEv'></fieldset></dl></div>

        <legend id='OOqEv'><style id='OOqEv'><dir id='OOqEv'><q id='OOqEv'></q></dir></style></legend>

            <bdo id='OOqEv'></bdo><ul id='OOqEv'></ul>

            <small id='OOqEv'></small><noframes id='OOqEv'>

              <tbody id='OOqEv'></tbody>
                • <tfoot id='OOqEv'></tfoot>
                  本文介绍了在 MySQL 中存储多对多关系的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  假设我有一个包含posts"和tags"表的简单数据库.帖子可以有多个标签,标签可以属于多个帖子.

                  Let's say I have a simple database with tables 'posts' and 'tags'. Posts can have many tags and tags can belong to many posts.

                  构建数据库的最佳方式是什么?我想过使用列表/序列化:

                  What is the best way to structure the database? I thought of using a list/serialize:

                  tags
                  idx tag_id, str tag_name
                  
                  posts
                  idx post_id, str title, list tag_ids
                  

                  或者有另一个带有关联的表.问题是使用这个我什至不知道如何构建查询以在收到帖子时提取关联的标签名称.

                  OR having another table with the associations. Problem is using this I don't even know how to structure the query to pull the associated tag names when I get a post.

                  posts
                  idx post_id, str title
                  
                  post_tags
                  fk post_id, fk tag_id
                  

                  其实我一个都不喜欢.有没有更好的办法?

                  I actually I don't like either of them. Is there a better way?

                  推荐答案

                  post_tags 是在数据库中实现多对多关系的正确方法.

                  The post_tags is the proper means of implementing a many to many relationship in the database.

                  我对您发布的内容所做的唯一补充是,其中的两列都应该是主键,以确保没有重复项.

                  The only addition I'd make to what you posted is that both columns in it should be the primary key to ensure there are no duplicates.

                  这篇关于在 MySQL 中存储多对多关系的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:MySQL 日期时间索引不起作用 下一篇:如何将空值传递给外键字段?

                  相关文章

                  <legend id='aaK3q'><style id='aaK3q'><dir id='aaK3q'><q id='aaK3q'></q></dir></style></legend>

                      <small id='aaK3q'></small><noframes id='aaK3q'>

                      <tfoot id='aaK3q'></tfoot>
                      <i id='aaK3q'><tr id='aaK3q'><dt id='aaK3q'><q id='aaK3q'><span id='aaK3q'><b id='aaK3q'><form id='aaK3q'><ins id='aaK3q'></ins><ul id='aaK3q'></ul><sub id='aaK3q'></sub></form><legend id='aaK3q'></legend><bdo id='aaK3q'><pre id='aaK3q'><center id='aaK3q'></center></pre></bdo></b><th id='aaK3q'></th></span></q></dt></tr></i><div id='aaK3q'><tfoot id='aaK3q'></tfoot><dl id='aaK3q'><fieldset id='aaK3q'></fieldset></dl></div>
                      • <bdo id='aaK3q'></bdo><ul id='aaK3q'></ul>