1

Im not sure what is wrong with my create table here. Keeps giving me error

ERROR 1064 (42000): 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 'character
(
character_id VarChar(15) PRIMARY KEY,
name VarChar(30) NOT NULL,
sex' at line 1

I dont see any errors in it?

CREATE TABLE character
(
character_id VarChar(15) PRIMARY KEY,
name VarChar(30) NOT NULL,
sex VarChar(7) NOT NULL,
age INT NOT NULL,
hair VarChar(10) NOT NULL,
eye VarChar(10) NOT NULL,
skin VarChar(12) NOT NULL,
body VarChar(12) NOT NULL,
from VarChar(20) NOT NULL
) engine=innobd;
0

4 Answers 4

3

character and from are reserved words in MySQL: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

To use a reserved word as a field/table identifier, you'll have to quote it with backticks:

create table `character` (
...
body VarChar(12) NOT NULL,
`from` VarChar(20) NOT NULL
...
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I knew that as soon as you said I just thought fail.
0

Both from and character are special words reserved by the database vendor. Try, for example, naming a column "limit" and you will get the same result. Re-name the table and the column from and your problem will go away.

Comments

0
CREATE TABLE 'character'
(
character_id VarChar(15) PRIMARY KEY,
name VarChar(30) NOT NULL,
sex VarChar(7) NOT NULL,
age INT NOT NULL,
hair VarChar(10) NOT NULL,
eye VarChar(10) NOT NULL,
skin VarChar(12) NOT NULL,
body VarChar(12) NOT NULL,
from VarChar(20) NOT NULL
) engine=innobd;

you're trying to use a reserved word so you need to add backtick to the table name, My suggestion is to change the table name, and avoid using reserved words

Comments

0

Two problems:

  1. The table name "character" should be characters, character is a reserved word
  2. The field name "from" should be different than the SQL keyword FROM

This should work:

CREATE TABLE characters
(
character_id VarChar(15) PRIMARY KEY,
name VarChar(30) NOT NULL,
sex VarChar(7) NOT NULL,
age INT NOT NULL,
hair VarChar(10) NOT NULL,
eye VarChar(10) NOT NULL,
skin VarChar(12) NOT NULL,
body VarChar(12) NOT NULL,
fromX VarChar(20) NOT NULL
) engine=innobd;

Hope this help.

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.