3

Could someone please tell me why I am getting this error and what I should change!

mysql_exceptions.ProgrammingError: (1064, "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 'ORDER int,\n
FOREIGN KEY (ID) REFERENCES papers(ID),\n PRIMARY K' at line 4")

This is my statement:

""" CREATE TABLE Authors (
    ID        int NOT NULL,
    AUTHOR   varchar(255),
    ORDER     int,
    FOREIGN KEY (ID) REFERENCES papers(ID),
    PRIMARY KEY (ID, ORDER)
    ) """

Thank you I am new to sql and simply cannot spot where I have gone wrong!

1 Answer 1

3

"ORDER" is a reserved word and cannot be used as a field name...

Select * from Author order by order;

https://dev.mysql.com/doc/refman/5.5/en/keywords.html

If you absolutely want to use order as a field name, you must quote it, but it is better to avoid it, since you also would need to quote it in any sql sentence refering it.

Sign up to request clarification or add additional context in comments.

1 Comment

Glad I could help. please marked the answer as accepted (which also will give you some extra so-points)

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.