0

I'm trying to do something pretty simple - add a table to my database through phpMyAdmin. For some reason the following throws up 5 errors:

CREATE TABLE group (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255)
) DEFAULT CHARACTER SET utf8 ENGINE=InnoDB

phpMyAdmin tells me that the following is wrong about it.

The name of the entity was expected. (near "group" at position 13) An opening bracket was expected. (near "group" at position 13) At least one column definition was expected. (near " " at position 12) Unexpected beginning of statement. (near "id" at position 26) Unrecognized statement type. (near "INT" at position 29)

I'm wondering why this error comes about, and whether I can do anything to fix it.

Francisco
  • 10,918
  • 6
  • 34
  • 45

2 Answers2

0

Use single tick marks around the word "group" like this:

CREATE TABLE `group` (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255)
) DEFAULT CHARACTER SET utf8 ENGINE=InnoDB

The problem is "group" is a reserved word. You can learn more about that here: https://dev.mysql.com/doc/refman/5.5/en/keywords.html

mayersdesign
  • 5,062
  • 4
  • 35
  • 47
  • the question is: *"why?" - there is a specific reason. (as per original post http://stackoverflow.com/revisions/43263151/1) – Funk Forty Niner Apr 06 '17 at 18:32
  • @ Fred -ii- I added your link, but to be pedantic, that wasn't the question ;) Although of course it's useful to explain the answer :) – mayersdesign Apr 06 '17 at 18:34
  • *"that wasn't the question"* - It should be, IMHO. Say I hadn't closed the question with the duplicate for the often-asked problem where 95% of the time they don't Google their error (which was the case here, I'm sure), the OP or anyone else visiting the question/answer and not knowing the reason why, how else will they know? Think about it and put yourself in their shoes ;-) we were all once 'there" at one time. – Funk Forty Niner Apr 06 '17 at 18:38
  • Thank you, this worked for me :) – wordsinthemind Apr 06 '17 at 18:44
0

"group" is a reserved keyword in MySQL, you'll need to wrap it in the back tick character like so to escape that:

    CREATE TABLE `group` (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255)
) DEFAULT CHARACTER SET utf8 ENGINE=InnoDB
AlexGW
  • 21
  • 3