我目前正在学习使用popsql ide的SQL。我正在尝试运行命令来创建表,但我一直收到
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代码
--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');发布于 2020-11-08 10:42:10
错误消息是正确的:当您有疑问时,应该参考手册。
来自the MySQL documentation on comments
从--序列到行尾的
。在MySQL中,双划线
--(双破折号)注释样式要求第二个破折号后跟至少一个空格或控制字符(如空格、制表符、换行符等)。
您没有这样做,所以您的语法是无效的。
https://stackoverflow.com/questions/64734337
复制相似问题