• <bdo id='s3EJ8'></bdo><ul id='s3EJ8'></ul>

      1. <small id='s3EJ8'></small><noframes id='s3EJ8'>

        <tfoot id='s3EJ8'></tfoot>

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

        MySQL 关系

        时间:2023-11-28

          1. <small id='VGv0B'></small><noframes id='VGv0B'>

              <tbody id='VGv0B'></tbody>
            <legend id='VGv0B'><style id='VGv0B'><dir id='VGv0B'><q id='VGv0B'></q></dir></style></legend>
            • <bdo id='VGv0B'></bdo><ul id='VGv0B'></ul>

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

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

                  问题描述

                  我想弄清楚如何构建这个数据库.我之前用过苹果的核心数据就好了,我现在只是在做一个需要 MySQL 的不同项目.我对 MySQL 很陌生,所以请放轻松.:)

                  I am trying to figure out how to structure this database. I have used Apple's core data before just fine, I'm just working on a different project now that requires MySQL. I am very new to MySQL so please go easy on me. :)

                  在这个例子中,假设我有三个表,UserDeviceLocation.推导出来,一个Location可以有多个Device,而Device只能有一个Location;每个 User 都有它的主键,UserID,我需要使用它来获取正确的信息.

                  For this example, let's say I have three tables, User, Device, and Location. Drawing it out, a Location can have many Devices, but the Device can only have one Location; Each User has its primary key, UserID, of which I need to use to fetch the correct information.

                  那么我如何在这里建立这样的关系?我听说过创建索引和外键,但我不确定它们是如何工作的.

                  So how do I create a relationship like this here? I've heard of creating an index and a foreign key and I'm not sure how they work exactly.

                  最后,我需要做的是能够访问 User 的特定表并查看与该 User 关联的所有 Locations.我还需要能够在某个 Location 为某个 User 添加一个 Device.

                  In the end, what I need to do is be able to access the User's specific table and view all of the Locations associated with that User. I will also need to be able to add a Device at a certain Location for a certain User.

                  再一次,请原谅我,因为我正试图将我的头围绕在 MySQL 上.我正在使用 HeidiSQL 进行数据库编辑.

                  Again, please forgive me as I'm trying to wrap my head around MySQL. I am using HeidiSQL to do my database editing.

                  推荐答案

                  User - Device 是多对多关系,因此您需要引入一个中间表来解决该关系.该表仅由两个外键组成,一个引用用户表,一个引用设备.设备 - 可以使用设备表中指向位置表的简单外键来处理位置.

                  User - Device is a many-to-many relationship, so you'll want to introduce an intermediary table to resolve that relationship. That table simply consists of two foreign keys, one referencing the User table and one referencing Device. Device - Location can be handled with a simple foreign key in the Device table pointing to a Location table.

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

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

                    <tbody id='asQjc'></tbody>

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

                        • <bdo id='asQjc'></bdo><ul id='asQjc'></ul>
                        • <tfoot id='asQjc'></tfoot>

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