0

I wont to create sql tables but I receive error.

#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 ,
)
2
  • Looks like you have a stray comma at the end of articles_ratings and also forgot the ; to terminate the first CREATE TABLE statement, which is why MySQL points to a syntax error at the start of the second CREATE TABLE. Commented Mar 26, 2012 at 13:25
  • @kazik1616 Ah yes, the elusive archaeology badge Commented Aug 24, 2015 at 9:40

1 Answer 1

1

Add the primary key to your articles ratings statement or remove the last comma.

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 ) 
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.