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

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

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

        复合键作为外键(sql)

        Composite key as foreign key (sql)(复合键作为外键(sql))
        <i id='nJLBh'><tr id='nJLBh'><dt id='nJLBh'><q id='nJLBh'><span id='nJLBh'><b id='nJLBh'><form id='nJLBh'><ins id='nJLBh'></ins><ul id='nJLBh'></ul><sub id='nJLBh'></sub></form><legend id='nJLBh'></legend><bdo id='nJLBh'><pre id='nJLBh'><center id='nJLBh'></center></pre></bdo></b><th id='nJLBh'></th></span></q></dt></tr></i><div id='nJLBh'><tfoot id='nJLBh'></tfoot><dl id='nJLBh'><fieldset id='nJLBh'></fieldset></dl></div>

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

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

              • <tfoot id='nJLBh'></tfoot>
                    <tbody id='nJLBh'></tbody>
                1. <legend id='nJLBh'><style id='nJLBh'><dir id='nJLBh'><q id='nJLBh'></q></dir></style></legend>
                  本文介绍了复合键作为外键(sql)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这是我关注的两个表:

                  CREATE TABLE IF NOT EXISTS `tutorial` (
                    `beggingTime` time NOT NULL,
                    `day` varchar(8) NOT NULL,
                    `tutorId` int(3) NOT NULL,
                    `maxMembers` int(2) NOT NULL,
                    `minMembers` int(1) NOT NULL,
                    PRIMARY KEY (`beggingTime`,`day`,`tutorId`),
                    KEY `tutorId` (`tutorId`)
                  ) 
                  
                  
                  CREATE TABLE IF NOT EXISTS `group` (
                    `groupId` tinyint(3) NOT NULL AUTO_INCREMENT,
                    `status` varchar(20) NOT NULL,
                    `groupName` varchar(50) NOT NULL,
                    PRIMARY KEY (`groupId`)
                  ) 
                  

                  我想在组"中创建一个字段,该字段将链接到教程"中的复合唯一键.所以我想我的问题是,我如何关联这些表?我是否必须为教程"中的每个主键在组"中创建外键字段?

                  I would like to create a field in 'group' that would link to the composite unique keys in 'tutorial'. So I guess my question is, how do I relate these tables? do I have to to create foreign keys field in 'group' for each primary key in 'tutorial'?

                  推荐答案

                  根据 mySQL 文档,您应该能够设置到组合的外键映射,这将需要您创建多个列.

                  Per the mySQL documentation you should be able to set up a foreign key mapping to composites, which will require you to create the multiple columns.

                  添加列并将其放入您的 group

                  Add the columns and put this in your group table

                  FOREIGN KEY (`beggingTime`,`day`,`tutorId`) 
                      REFERENCES tutorial(`beggingTime`,`day`,`tutorId`)
                  

                  正如 Steven 在下面的评论中提到的,您应该尝试重新构建它,以便教程表使用实际的主键(即使它只是一个身份代理键).这将提高性能,因为 SQL 是为这种类型的关系构建的,而不是复合关系.

                  As Steven has alluded to in the below comments, you SHOULD try to re-architect this so that the tutorial table uses an actual primary key (even if it is just an identity surrogate key). This will allow for greater performance as SQL was built for this type of relationship, not composite.

                  这篇关于复合键作为外键(sql)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to delete duplicate records in mysql database?(如何删除mysql数据库中的重复记录?)
                  Python Pandas write to sql with NaN values(Python Pandas 使用 NaN 值写入 sql)
                  MySQL Insert amp; Joins(MySQL 插入 amp;加入)
                  MySQL concat() to create column names to be used in a query?(MySQL concat() 创建要在查询中使用的列名?)
                  NodeJS responded MySQL timezone is different when I fetch directly from MySQL(当我直接从 MySQL 获取时,NodeJS 响应 MySQL 时区不同)
                  WHERE datetime older than some time (eg. 15 minutes)(WHERE 日期时间早于某个时间(例如 15 分钟))
                      <tbody id='2DPNT'></tbody>
                  • <small id='2DPNT'></small><noframes id='2DPNT'>

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