当前位置: 首页 > 面试题库 >

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

陶飞英
2023-03-14
问题内容

我有一个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,
);

当我运行它时,我得到一个错误:

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

问题答案:

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

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



 类似资料: