0

I'm a beginner programmer in MySQL. When I'm creating a table called message in my database called chat, this is the error:

Error creating Table: 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 'from CHAR(30),to TEXT(300),text TEXT(1000),index INT(10) NOT NULL AUTO_INCREMENT' at line 1

The full MySQL statement is:

CREATE TABLE message(date DATE,from CHAR(30),to TEXT(300),text TEXT(1000),index INT(10) NOT NULL AUTO_INCREMENT,PRIMARY KEY(index))

I know the other code is correct, because I created another table previously, and it worked fine. I then copied the code and used it for this statement.

It's probably a really silly mistake, but I can't figure it out.

Please help. Thanks in advance.

1

2 Answers 2

2

to, from and index are reserved words.

Try:

CREATE TABLE message(date DATE,`from` CHAR(30),`to` TEXT(300),text TEXT(1000),`index` INT(10) NOT NULL AUTO_INCREMENT,PRIMARY KEY(`index`))
Sign up to request clarification or add additional context in comments.

1 Comment

You have to quote the last index occurrence, too.
1

from is a mysql reserved words,

you must add from in `,

UPDATE: to,index is key too, here the right sql

CREATE TABLE message(date DATE,`from` CHAR(30),`to` TEXT(300),text TEXT(1000),`index` INT(10) NOT NULL AUTO_INCREMENT,PRIMARY KEY(`index`))

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.