MySQL 键:主键、外键、键——什么是“KEY”?
查看“mysqldump -d”并看到一个键是 KEY,而不是“PRIMARY KEY”或“FOREIGN KEY”
什么是 KEY?
示例:
CREATE TABLE IF NOT EXISTS `TABLE_001` (
`COL_001` int(256) NOT NULL,
`COL_002` int(256) NOT NULL,
`COL_003` int(256) NOT NULL,
`COL_004` int(256) NOT NULL,
`COL_005` int(256) NOT NULL,
`COL_006` int(256) NOT NULL,
`COL_007` int(256) NOT NULL,
`COL_008` int(256) NOT NULL,
`COL_009` int(256) NOT NULL,
`COL_010` int(256) NOT NULL,
`COL_011` int(256) NOT NULL,
`COL_012` int(256) NOT NULL,
PRIMARY KEY (`COL_001`),
KEY `COL_002` (`COL_002`,`COL_003`),
KEY `COL_012` (`COL_012`),
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
另外,当我创建此表的新版本时,除了将“ENGINE=MyISAM”更改为“ENGINE=InnoDB”之外,将 MyISAM 更改为 InnoDB 是否还需要进行任何其他更改?
Looking at a "mysqldump -d" and see a key that is KEY, not "PRIMARY KEY" or "FOREIGN KEY"
What is KEY?
Example:
CREATE TABLE IF NOT EXISTS `TABLE_001` (
`COL_001` int(256) NOT NULL,
`COL_002` int(256) NOT NULL,
`COL_003` int(256) NOT NULL,
`COL_004` int(256) NOT NULL,
`COL_005` int(256) NOT NULL,
`COL_006` int(256) NOT NULL,
`COL_007` int(256) NOT NULL,
`COL_008` int(256) NOT NULL,
`COL_009` int(256) NOT NULL,
`COL_010` int(256) NOT NULL,
`COL_011` int(256) NOT NULL,
`COL_012` int(256) NOT NULL,
PRIMARY KEY (`COL_001`),
KEY `COL_002` (`COL_002`,`COL_003`),
KEY `COL_012` (`COL_012`),
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Also, when I'm create a new version of this table, will changing MyISAM to InnoDB require any additional changes besides "ENGINE=MyISAM" to "ENGINE=InnoDB"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
KEY
是索引声明的替代语法。 CREATE TABLE 语句包括在 COL_002 上创建两个索引和 COL_012 分别。不,这应该没问题,但要注意,您不能在使用 Innodb 引擎的表上使用 MySQL 的本机全文搜索 (FTS)——它们必须是 MyISAM,然后才能对其中的列进行全文索引。
KEY
is alternative syntax for index declaration. The CREATE TABLE statement includes creating two indexes, on COL_002 and COL_012 separately.No, that should be fine but be aware that you can't use MySQL's native Full Text Search (FTS) on tables using the Innodb engine -- they have to be MyISAM before you can full text index columns in them.
来自 CREATE TABLE 语法的 MySQL 手册:
From MySQL manual for CREATE TABLE syntax: