初学者@ SQL:SQL查询错误

时间:2014-09-20 00:34:34

标签: php mysql sql

我正在尝试输入此数据作为示例来学习sql但是出现此错误
#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 ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci' at line 5
这是我的SQL代码:

CREATE TABLE IF NOT EXISTS `majors` (
  `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `price` decimal(10,2) DEFAULT NULL,
  `about` varchar(500) COLLATE utf8_unicode_ci DEFAULT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

INSERT INTO `majors` (`name`, `price`, `about`) VALUES('Applied Physics', 20.00, 'Applied Physics');
INSERT INTO `majors` (`name`, `price`, `about`) VALUES('Computer Science', 15.00, 'Computer Science');

1 个答案:

答案 0 :(得分:2)

删除DEFAULT NULL后的逗号:

CREATE TABLE IF NOT EXISTS `majors` (
  `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `price` decimal(10,2) DEFAULT NULL,
  `about` varchar(500) COLLATE utf8_unicode_ci DEFAULT NULL,   <-- remove the comma
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

http://sqlfiddle.com/#!2/a2694