MySQL ERROR 1064 (42000):您的 SQL 语法有错误;

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18742492/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:48:24  来源:igfitidea点击:

ERROR 1064 (42000): You have an error in your SQL syntax;

mysqlsql

提问by SkyStar

I have a MySQL commands:

我有一个 MySQL 命令:

CREATE DATABASE IF NOT EXISTS courses;

USE courses

CREATE TABLE IF NOT EXISTS teachers(
    id INT(10) UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
    name VAR_CHAR(50) NOT NULL,
    addr VAR_CHAR(255) NOT NULL,
    phone INT NOT NULL,
);

When I run it, I get an 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 to use near 'VAR_CHAR(50) NOT NULL, addr VAR_CHAR(255) NOT
NULL, phone INT NOT NULL, )' at line 3

回答by juergen d

It is varcharand not var_char

它是varchar和不是var_char

CREATE DATABASE IF NOT EXISTS courses;

USE courses;

CREATE TABLE IF NOT EXISTS teachers(
    id INT(10) UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
    name VARCHAR(50) NOT NULL,
    addr VARCHAR(255) NOT NULL,
    phone INT NOT NULL
);

You should use a SQL tool to visualize possbile errors like MySQL Workbench.

您应该使用 SQL 工具来可视化可能的错误,例如MySQL Workbench

回答by Sathish D

Try this:

尝试这个:

Use back-ticks for NAME

对 NAME 使用反引号

CREATE TABLE `teachers` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `addr` varchar(255) NOT NULL,
  `phone` int(10) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

回答by Akshay Katiha

Use varchar instead of VAR_CHAR and omit the comma in the last line i.e.phone INT NOT NULL );. The last line during creating table is kept "comma free". Ex:- CREATE TABLE COMPUTER ( Model varchar(50) ); Here, since we have only one column ,that's why there is no comma used during entire code.

使用 varchar 而不是 VAR_CHAR 并省略最后一行中的逗号 iephone INT NOT NULL );。创建表期间的最后一行保持“无逗号”。例如:- 创建表计算机(模型 varchar(50) );在这里,由于我们只有一列,这就是为什么在整个代码中没有使用逗号。