我目前正在使用 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');