首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么PopSQL要求我检查手册?

为什么PopSQL要求我检查手册?
EN

Stack Overflow用户
提问于 2020-11-08 10:40:09
回答 1查看 133关注 0票数 0

我目前正在学习使用popsql ide的SQL。我正在尝试运行命令来创建表,但我一直收到

代码语言:javascript
复制
ER_PARSE_ERROR: 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 '--auto increment automatically adds 1 to the primary key-- name VARCHAR(20) ' at line 2

我做错了什么?以下是sql代码

代码语言:javascript
复制
--writing table in all caps differentiates it from other phrases
--the keyword phrase NOT NULL indicates that the column has to have a value in it at every row
--the UNIQUE keyphrase indicates that the column values have to be unique 

CREATE TABLE student (
    student_id INT AUTO_INCREMENT,--auto increment automatically adds 1 to the primary key
    name VARCHAR(20) NOT NULL,
    major VARCHAR (20) UNIQUE,
    age INT DEFAULT 'undecided', --the DEFAULT keyword will populate a particular row with phrase in quotes if there is no info entered
    PRIMARY KEY(student_id)
); 
--constraints are rules that we set in our db to control what happens to info.
--creating a rule such that a particular keyword should populate a row when no data is in it is a constraint  
DESCRIBE student;
--the keyword 'DROP' deletes any item that we specify--

DROP TABLE student;

--THIS LINE ADDS THE GPA COLUMN TO OUR TABLE--
ALTER TABLE student ADD gpa DECIMAL(3,2);

--this command displays the info that's currently in the table
SELECT * FROM student;

--INSERTING DATA INTO THE TABLE
--the order in which the tables were created should be the order in whcich they should be inserted into the table
--INSERT INTO student VALUES (2,'Rose', 'Chemistry',3.23);

--you can specify what values to add to the database if you don't have a particular key 
INSERT INTO student(name, major) VALUES('John', 'Chemistry');
EN

回答 1

Stack Overflow用户

发布于 2020-11-08 10:42:10

错误消息是正确的:当您有疑问时,应该参考手册。

来自the MySQL documentation on comments

--序列到行尾的

。在MySQL中,双划线-- (双破折号)注释样式要求第二个破折号后跟至少一个空格或控制字符(如空格、制表符、换行符等)。

您没有这样做,所以您的语法是无效的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64734337

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档