我就直接po截图和代码
#
alter table testMyIndex add (hometown VARCHAR(45) KEY,money FLOAT UNIQUE); #正确
#报错了,Multiple primary key defined 提示已经有primary key(主键)了
#alter table testMyIndex add (remarks VARCHAR(50) KEY,bankNumber VARCHAR(16) UNIQUE);
报错信息[Err] 1068 - Multiple primary key defined
我记得key关键字可以用来声明普通索引,怎么此时key关键字又有primary key的作用了?
我把创建表的语句拷贝出来
#查看创建表的语句
SHOW CREATE TABLE testMyIndex;
#我把创建表的语句拷贝出来
CREATE TABLE `testmyindex` (
`xing` varchar(30) DEFAULT NULL,
`ming` varchar(20) DEFAULT NULL,
`email` varchar(30) DEFAULT NULL,
`workCity` varchar(30) DEFAULT NULL,
`schoolName` varchar(40) DEFAULT NULL,
`hometown` varchar(45) NOT NULL,
`money` float DEFAULT NULL,
PRIMARY KEY (`hometown`),
UNIQUE KEY `index_email` (`email`),
UNIQUE KEY `index_workCity2` (`workCity`),
UNIQUE KEY `index_schoolName_workCity2` (`schoolName`,`workCity`),
UNIQUE KEY `index_schoolName2` (`schoolName`),
UNIQUE KEY `money` (`money`),
KEY `xm` (`xing`,`ming`),
KEY `index_workCity` (`workCity`),
KEY `index_schoolName_workCity` (`schoolName`,`workCity`),
KEY `index_schoolName` (`schoolName`)
) ENGINE=InnoDB DEFAULT CHARSET=gb2312