下面是一张创建的数据表:
CREATE TABLE `cms_news` (
`news_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`catid` smallint(5) unsigned NOT NULL DEFAULT “0”,
`title` varchar(80) NOT NULL DEFAULT “”,
`small_title` varchar(30) NOT NULL DEFAULT “”,
`title_font_color` varchar(250) DEFAULT NULL COMMENT “标题颜色”,
`thumb` varchar(100) NOT NULL DEFAULT “”,
`keywords` char(40) NOT NULL DEFAULT “”,
`description` varchar(250) NOT NULL COMMENT “文章描述”,
`posids` varchar(250) NOT NULL DEFAULT “”,
`listorder` tinyint(3) unsigned NOT NULL DEFAULT “0”,
`status` tinyint(1) NOT NULL DEFAULT “1”,
`copyfrom` varchar(250) DEFAULT NULL COMMENT “来源”,
`username` char(20) NOT NULL,
`create_time` int(10) unsigned NOT NULL DEFAULT “0”,
`update_time` int(10) unsigned NOT NULL DEFAULT “0”,
PRIMARY KEY (`news_id`),
KEY `status` (`status`,`listorder`,`news_id`),
KEY `listorder` (`catid`,`status`,`listorder`,`news_id`),
KEY `catid` (`catid`,`status`,`news_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
问题:除了PRIMARY KEY 之外,为啥其它的还要加3个KEY 呢,换句话说:
KEY `status` (`status`,`listorder`,`news_id`),
KEY `listorder` (`catid`,`status`,`listorder`,`news_id`),
KEY `catid` (`catid`,`status`,`news_id`)
该表在写入mysql中出现了以下错误:
MySQL 返回: 文档
#1064 – Erreur de syntaxe près de “PRIMARY KEY (`news_id`),
KEY `status` (`status`,`listorder`,`news_id`),
KE” Ã la ligne 14
是啥意思? 求高手指点一二,谢谢!
CREATE TABLE `cms_news` (
`news_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`catid` smallint(5) unsigned NOT NULL DEFAULT “0”,
`title` varchar(80) NOT NULL DEFAULT “”,
`small_title` varchar(30) NOT NULL DEFAULT “”,
`title_font_color` varchar(250) DEFAULT NULL COMMENT “标题颜色”,
`thumb` varchar(100) NOT NULL DEFAULT “”,
`keywords` char(40) NOT NULL DEFAULT “”,
`description` varchar(250) NOT NULL COMMENT “文章描述”,
`posids` varchar(250) NOT NULL DEFAULT “”,
`listorder` tinyint(3) unsigned NOT NULL DEFAULT “0”,
`status` tinyint(1) NOT NULL DEFAULT “1”,
`copyfrom` varchar(250) DEFAULT NULL COMMENT “来源”,
`username` char(20) NOT NULL,
`create_time` int(10) unsigned NOT NULL DEFAULT “0”,
`update_time` int(10) unsigned NOT NULL DEFAULT “0”,
PRIMARY KEY (`news_id`),
KEY `status` (`status`,`listorder`,`news_id`),
KEY `listorder` (`catid`,`status`,`listorder`,`news_id`),
KEY `catid` (`catid`,`status`,`news_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
问题:除了PRIMARY KEY 之外,为啥其它的还要加3个KEY 呢,换句话说:
KEY `status` (`status`,`listorder`,`news_id`),
KEY `listorder` (`catid`,`status`,`listorder`,`news_id`),
KEY `catid` (`catid`,`status`,`news_id`)
该表在写入mysql中出现了以下错误:
MySQL 返回: 文档
#1064 – Erreur de syntaxe près de “PRIMARY KEY (`news_id`),
KEY `status` (`status`,`listorder`,`news_id`),
KE” Ã la ligne 14
是啥意思? 求高手指点一二,谢谢!
解决方案
20
原样照抄复制下面代码不做任何修改然后再试。假如有问题把中文去掉再试。你原来的语句中含不可见字符。
CREATE TABLE `cms_news` ( `news_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `catid` smallint(5) unsigned NOT NULL DEFAULT "0", `title` varchar(80) NOT NULL DEFAULT "", `small_title` varchar(30) NOT NULL DEFAULT "", `title_font_color` varchar(250) DEFAULT NULL COMMENT "标题颜色", `thumb` varchar(100) NOT NULL DEFAULT "", `keywords` char(40) NOT NULL DEFAULT "", `description` varchar(250) NOT NULL COMMENT "文章描述", `posids` varchar(250) NOT NULL DEFAULT "", `listorder` tinyint(3) unsigned NOT NULL DEFAULT "0", `status` tinyint(1) NOT NULL DEFAULT "1", `copyfrom` varchar(250) DEFAULT NULL COMMENT "来源", `username` char(20) NOT NULL, `create_time` int(10) unsigned NOT NULL DEFAULT "0", `update_time` int(10) unsigned NOT NULL DEFAULT "0", PRIMARY KEY (`news_id`), KEY `status` (`status`,`listorder`,`news_id`), KEY `listorder` (`catid`,`status`,`listorder`,`news_id`), KEY `catid` (`catid`,`status`,`news_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
20
添加必要的索引。