将 MyISAM 转换为 InnoDB,其中表具有两列(复合)PK,其中之一是自动增量
我想将一些 MyISAM 表转换为 InnoDB,这样我就可以利用外键支持。然而,大多数表都使用两列(复合)主键设计,其中其中一个列是自动增量列(这样做是出于历史原因,并且还确保自动增量列可以充当一种在其他列值的上下文中记录的增量键)
我意识到我们需要取消多列主键才能使用自动增量和 InnoDB。不过,我们有数千条记录,并且这些记录与其他表有关系。
有没有关于如何将这些表转换为 InnoDB 的提示?我想出的唯一方法是首先在每个表中添加一个新列,将其设置为唯一的自动增量主键,然后使用脚本更新依赖表以指向新的(真正唯一的)主键。
谢谢 史蒂夫
I would like to convert some of our MyISAM tables to InnoDB so I can take advantage of foreign key support. However, most of the tables use a two-column (composite) primary key design in which one of those columns is an auto-increment (this was done for historical reasons and also ensured that the auto-increment column could act as a kind of incremental key for records within the context of the other column's value)
I realize that we need to do away with the multi-column primary key in order to use auto-increment and InnoDB. We have thousands of records though and these records have relationships to other tables.
Are there any tips on how to convert these tables to InnoDB? The only method I've come up with is to first add a new column in each table, set it as the sole auto-increment primary key and then use scripts to update the dependent tables to point to the new (truly unique) primary key.
Thanks
Steve
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 MySQL 5.0 及更高版本中,您可以将自动增量列作为主键的一部分,但它必须是索引中的第一个字段。
*...AUTO_INCRMENT 列必须显示为 InnoDB 表索引中的第一列...*
在此处检查文档条目 http://dev.mysql.com/doc/refman/5.0/en/innodb-auto-increment-handling.html
In MySQL 5.0 and greater versions you can include the auto-increment column as part of the primary key, but it has to be the first field in the index.
*...An AUTO_INCREMENT column must appear as the first column in an index on an InnoDB table...*
Check the documentation entry here http://dev.mysql.com/doc/refman/5.0/en/innodb-auto-increment-handling.html