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.

1

2 Answers 2

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

4
  • the question is: *"why?" - there is a specific reason. (as per original post stackoverflow.com/revisions/43263151/1) Apr 6, 2017 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 :) Apr 6, 2017 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. Apr 6, 2017 at 18:38
  • Thank you, this worked for me :) Apr 6, 2017 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
1
  • Thanks, this worked just fine with back ticks. Apr 6, 2017 at 18:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.