blunders
blunders

Reputation: 3669

MySQL keys: PRIMARY KEY, FOREIGN KEY, KEY -- what is "KEY"?

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"?

Upvotes: 1

Views: 268

Answers (2)

codaddict
codaddict

Reputation: 455020

From MySQL manual for CREATE TABLE syntax:

KEY is normally a synonym for INDEX.

Upvotes: 2

OMG Ponies
OMG Ponies

Reputation: 332571

KEY is alternative syntax for index declaration. The CREATE TABLE statement includes creating two indexes, on COL_002 and COL_012 separately.

...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"?

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.

Upvotes: 4

Related Questions