tags:

views:

1117

answers:

2

Hi this is my code and it returns "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 'VALUE, chapter VARCHAR(100) CHARACTER SET utf8 COLLA' at line 2"

CREATE TABLE IF NOT EXISTS texts (
id SERIAL DEFAULT VALUE,
chapter VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci,
text LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci,
uid INT NOT NULL AUTO_INCREMENT UNIQUE KEY,
time TIMESTAMP,
FULLTEXT (chapter)
)Engine = InnoDB;

I have no idea what is wrong, I was writing it according to MySQL documentation.

I also tried changing this column to

chapter VARCHAR(100) CHARACTER SET utf8, ...

but it returned the same error.

+1  A: 

The line:

id SERIAL DEFAULT VALUE,

is invalid. You need to specify a value for DEFAULT VALUE or take it out.

id SERIAL,

However you have 2 auto_increment fields in your table which is also invalid. Serial is just an alias for

BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT .
zodeus
Good answer. I think "VALUE" doesn't belong there either. No need to set a default value for an auto-increment column anyway.
Adam Bernier
A: 

Thank you, that's it. But I wonder what means this? It says SERIAL DEFAULT VALUE in the definition of an integer column is an alias for NOT NULL AUTO_INCREMENT UNIQUE. So why SERIAL DEFAULT VALUE is invalid?

perfectDay
If you're going to comment on my answer please use the "add comment" instead of posting a non answer. That being said however in order for "SERIAL DEFAULT VALUE" to work it would need to be formatted like this "MyNumberColumn INT SERIAL DEFAULT VALUE"
zodeus
I'm sorry, I should have used "add comment".
perfectDay