创建表时出现SQL语法错误 [英] SQL syntax error when creating table
问题描述
我使用MySQL
5.6命令行客户端创建一个简单的数据库,并且我可以创建数据库但尚未创建我的第一个表,但我遇到无法识别的语法错误.感谢您的帮助,如果英语拼写错误,这不是我的母语,对此我们深感抱歉.
请找到粘贴的SQL
语法错误:
I use MySQL
5.6 command line client to create a simple database and I can create database yet to create my first table I have a syntax error that I cannot identify. Thanks for your help and sorry if there are English mispells it is not my first language.
Please find pasted the SQL
syntax error:
mysql> USE SYLVAINTEST
Database changed
mysql> CREATE TABLE students
-> (
-> studentid INT NOT NULL,
-> firstname VARCHAR,
-> lastname VARCHAR,
-> dob VARCHAR,
-> CONSTRAINT pk_students PRIMARY KEY (studentid)
-> );
错误1064(42000):您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以获取在'附近使用的正确语法 姓VARCHAR, dob VARCHAR, 限制pk_students'位于第4行
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 ' lastname VARCHAR, dob VARCHAR, CONSTRAINT pk_students ' at line 4
mysql> CREATE TABLE students
-> (
-> studentid INT NOT NULL,
-> firstname VARCHAR ,
-> lastname VARCHAR ,
-> dob VARCHAR ,
-> CONSTRAINT pk_students PRIMARY KEY (studentid)
-> );
错误1064(42000):您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以获取在'附近使用的正确语法 姓VARCHAR, dob VARCHAR, 约束pk_students主键(在第4行
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 ' lastname VARCHAR , dob VARCHAR , CONSTRAINT pk_students PRIMARY KEY (' at line 4
推荐答案
您应在以下内容中为VARCHAR()
指定长度:
You should specify lenght for VARCHAR()
in following:
CREATE TABLE students
(
studentid INT NOT NULL,
firstname VARCHAR(40),
lastname VARCHAR(40),
dob VARCHAR(20),
CONSTRAINT pk_students PRIMARY KEY (studentid)
);
这篇关于创建表时出现SQL语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!