mySQL如何在SHOW CREATE TABLE中安排主键?

时间:2014-05-25 14:30:22

标签: mysql sql primary-key

我创建了一个表,这是SHOW CREATE TABLE所做的:

CREATE TABLE  `x` (
  `COMPETITION_ID` int(10) unsigned NOT NULL DEFAULT '0',
  `PLAYER1A_ID` int(10) unsigned NOT NULL DEFAULT '0',
  `PLAYER1B_ID` int(10) unsigned NOT NULL DEFAULT '0',
  `PLAYER2A_ID` int(10) unsigned NOT NULL DEFAULT '0',
  `PLAYER2B_ID` int(10) unsigned NOT NULL DEFAULT '0',
  `SCORE` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `DATEAT` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `REPLAY_ID` int(10) unsigned DEFAULT NULL,
  `ONTREE` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`PLAYER1A_ID`,`PLAYER1B_ID`,`PLAYER2A_ID`,`PLAYER2B_ID`,`COMPETITION_ID`,`ONTREE`),
  KEY `FK__2v2_ladder_3` (`PLAYER1B_ID`),
  KEY `FK__2v2_ladder_4` (`PLAYER2A_ID`),
  KEY `FK__2v2_ladder_5` (`PLAYER2B_ID`),
  KEY `FK__2v2_ladder_6` (`REPLAY_ID`),
  KEY `FK__2v2_ladder_1` (`COMPETITION_ID`),
  CONSTRAINT `FK__2v2_ladder_1` FOREIGN KEY (`COMPETITION_ID`) REFERENCES `competitions` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK__2v2_ladder_2` FOREIGN KEY (`PLAYER1A_ID`) REFERENCES `users` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK__2v2_ladder_3` FOREIGN KEY (`PLAYER1B_ID`) REFERENCES `users` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK__2v2_ladder_4` FOREIGN KEY (`PLAYER2A_ID`) REFERENCES `users` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK__2v2_ladder_5` FOREIGN KEY (`PLAYER2B_ID`) REFERENCES `users` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK__2v2_ladder_6` FOREIGN KEY (`REPLAY_ID`) REFERENCES `uploads` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED;

如果您检查PRIMARY KEY部分,您可以选择订单不是列顺序 - 它应该是COMPETITION_ID,PLAYER1A_ID,PLAYER1B_ID,PLAYER2A_ID,PLAYER2B_ID,ONTREE。 MySQL是如何安排的?它有多重要吗?

0 个答案:

没有答案