在MySQL中创建新表时出现SQL语法错误

时间:2012-03-26 13:19:04

标签: mysql

我不会创建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 
'CREATE TABLE `articles_ratings` ( `ID` INT(11) NOT NULL AUTO_INCREMENT, `a' at line 10
CREATE TABLE `articles` (
   `ID` int( 11 ) NOT NULL AUTO_INCREMENT ,
   `a_title` varchar( 255 ) ,
   `a_subtitle` tinytext,
   `a_content` text,
   PRIMARY KEY ( `ID` )
) 

CREATE TABLE `articles_ratings` (
   `ID` INT( 11 ) NOT NULL AUTO_INCREMENT ,
   `article_id` int( 11 ) NOT NULL ,
   `rating_value` tinyint( 2 ) NOT NULL ,
   `rater_ip` varchar( 20 ) NOT NULL ,
)

1 个答案:

答案 0 :(得分:1)

将主键添加到文章评级语句或删除最后一个逗号。

CREATE TABLE articles ( 
    ID int( 11 ) NOT NULL AUTO_INCREMENT , 
    a_title varchar( 255 ) , 
    a_subtitle tinytext, 
    a_content text, 
  PRIMARY KEY ( ID ) 
);
CREATE TABLE articles_ratings ( 
    ID INT( 11 ) NOT NULL AUTO_INCREMENT , 
  article_id int( 11 ) NOT NULL , 
  rating_value tinyint( 2 ) NOT NULL , 
  rater_ip varchar( 20 ) NOT NULL , 
PRIMARY KEY ( ID ) 
);