Mysql – ERROR 1064 (42000), when creating a thesql table

MySQLmysql-error-1064syntax-error

I am trying to create a table, but it gives me this 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 touse near ' INT NOT NULL AUTO_INCREMENT

Here is my code:

    CREATE TABLE bowling_scores (
    PlayerID, INT NOT NULL AUTO_INCREMENT
    , LName VARCHAR(100) NOT NULL
    , FName VARCHAR(100) NOT NULL
    , Game1 INT NULL
    , Game2 INT NULL
    , Game3 INT NULL
    , Game4 INT NULL
    , PRIMARY KEY (PlayerID)
    );

Best Answer

Here's a tip about syntax error messages: the message tells you where the error is.

check the manual that corresponds to your MySQL server version for the right syntax to use near ' INT NOT NULL AUTO_INCREMENT

This is telling you that MySQL became confused because it wasn't expecting to see that text. This usually means you made a mistake at that point, or immediately before it.

This can help you narrow down your search in the SQL statement to the point where it went wrong.

The error message also tells you what to do: check the manual. You should help yourself become better at SQL by reading documentation and examples.

I've been using MySQL for nearly 20 years, but I still refer to the reference docs every day. In fact, it's because I am experienced with MySQL that I know this is the right thing to do.

All SQL statements have a reference page in the manual. Here's the page for CREATE TABLE: https://dev.mysql.com/doc/refman/5.7/en/create-table.html

The MySQL manual is large, so it's easy to think "I don't know where the right page is." Gradually you can learn how the manual is organized. Pay attention to the hierarchy of links on the left column. When in doubt, just use Google for phrases like "mysql create table syntax".

You should be able to answer simple syntax errors for yourself instead of posting to Stack Overflow. You'll get your answer more quickly!