简体   繁体   English

创建mysql表时出现错误1064(42000)

[英]ERROR 1064 (42000), when creating a mysql table

I am trying to create a table, but it gives me this error: 我正在尝试创建表,但它给了我这个错误:

ERROR 1064 (42000): You have an error in your SQL syntax; 错误1064(42000):您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax touse near ' INT NOT NULL AUTO_INCREMENT 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在'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)
    );

This is an obvious error: 这是一个明显的错误:

PlayerID, INT NOT NULL AUTO_INCREMENT

You have an extraneous comma. 您有一个多余的逗号。 It should be: 它应该是:

PlayerID INT NOT NULL AUTO_INCREMENT

Stop putting commas on the next line of your SQL statements as well! 也不要在逗号的SQL语句的下一行加上逗号!

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 检查与您的MySQL服务器版本相对应的手册,以在'INT NOT NULL AUTO_INCREMENT附近使用正确的语法

This is telling you that MySQL became confused because it wasn't expecting to see that text. 这是在告诉您MySQL感到困惑,因为它不希望看到该文本。 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. 这可以帮助您将SQL语句中的搜索范围缩小到错误的位置。

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. 您应该通过阅读文档和示例来帮助自己更好地掌握SQL。

I've been using MySQL for nearly 20 years, but I still refer to the reference docs every day. 我已经使用MySQL近20年了,但是我仍然每天都参考参考文档。 In fact, it's because I am experienced with MySQL that I know this is the right thing to do. 实际上,这是因为我对MySQL很有经验,所以我知道这样做是正确的。

All SQL statements have a reference page in the manual. 所有SQL语句在手册中都有一个参考页。 Here's the page for CREATE TABLE: https://dev.mysql.com/doc/refman/5.7/en/create-table.html 这是创建表的页面: 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." MySQL手册很大,因此很容易想到“我不知道正确的页面在哪里”。 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". 如有疑问,只需将Google用于“ mysql create table语法”之类的短语即可。

You should be able to answer simple syntax errors for yourself instead of posting to Stack Overflow. 您应该能够自己回答简单的语法错误,而不是发布到Stack Overflow。 You'll get your answer more quickly! 您将更快地得到答案!

This should work. 这应该工作。 You had a comma after PlayerID PlayerID后您有一个逗号

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)
);

您应该编写类似以下内容的内容:

creat table Bowling_score(Playerid int, Firstname varchar(100), Lastname varchar(100), Game1 int, Game2 int, Game3 int);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM