这个简单的创建表查询难以理解的错误

时间:2012-10-09 01:41:17

标签: mysql sql phpmyadmin export

我刚刚使用phpmyadmin导出了一个奇异表的CREATE sql。这是结果:

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `register_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `account_type` int(11) NOT NULL,
  `active` int(11) NOT NULL,
  `email` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
  `login` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
  `password` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
  `name` varchar(200) COLLATE utf8_unicode_ci NOT NULL
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;

但是当我在phpmyadmin上运行此代码时,我收到此错误:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREME' at line 14

我尝试了很多方法,但我的技能还不够。

1 个答案:

答案 0 :(得分:4)

您忘记在PRIMARY KEY (id)

之前添加逗号
`name` varchar(200) COLLATE utf8_unicode_ci NOT NULL,   -- <== this
 PRIMARY KEY (`id`)

添加逗号即可,see this fiddle (click link)