SQL 代码不是 运行:可能是删除表和组织问题?

SQL Code not running: Drop Tables and Organization issue maybe?

所以,这是我的代码。当我尝试在学校提供的引擎中编译它时,我遇到了一些错误,每次我 运行 它们都会改变,但我目前拥有的是:

ERROR 1064 (42000) at line 123: 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 '9:30, 'L210', 103, 15), (86, 25, 2, 6/10/2007 9:30, 'L210', 107, 15), (89, 25, 5' at line 2

我已经试过去掉空格了,但没用。这与我获取信息的顺序有什么关系吗?还是其他原因?

我也不确定表格是否在第一步中删除。

/*Step One: Drop Tables*/
DROP TABLE IF EXISTS Student;
DROP TABLE IF EXISTS Zipcode;
DROP TABLE IF EXISTS Instructor;
DROP TABLE IF EXISTS Enrollment;
DROP TABLE IF EXISTS Sections;
DROP TABLE IF EXISTS Course;


/*Step Two: Create Tables*/
CREATE TABLE Zipcode
(
zip             int(11), 
city            varchar(25)     NOT NULL,  
state           varchar(2)      NOT NULL,
PRIMARY KEY (zip)
);

CREATE TABLE Student
(
student_ID          int(6)          UNIQUE,
salutation          varchar(5), 
first_name          varchar(25)     NOT NULL, 
last_name           varchar(25)     NOT NULL, 
street_address      varchar(50), 
phone               int(15)         NOT NULL, 
employer            varchar(50) , 
registration_date   date            NOT NULL, 
zip                 int(11),
PRIMARY KEY (student_ID),
FOREIGN KEY (zip) REFERENCES Zipcode (zip)
);

CREATE TABLE Course
(
    course_ID           int(6)          UNIQUE,
    description         varchar(50)     NOT NULL,
    cost                dec(8,2)        NOT NULL,
    prerequisite        int(6),
    PRIMARY KEY (course_ID),
    FOREIGN KEY (prerequisite) REFERENCES Course (course_ID)
);

CREATE TABLE Instructor
(
Instructor_ID   int(6)              UNIQUE,
salutation      varchar(5), 
first_name      varchar(25)         NOT NULL, 
last_name       varchar(25)         NOT NULL, 
street_address  varchar(50), 
zip             int(11)             NOT NULL,
PRIMARY KEY (Instructor_ID),
FOREIGN KEY (zip) REFERENCES zipcode (zip)
);

CREATE TABLE Sections
(
section_ID          int(8)          UNIQUE,
course_id           int(6)          NOT NULL,
course_section_num  int(6)          NOT NULL,
start_date_time     datetime        NOT NULL,
location            varchar(10),
instructor_ID       int(6)          NOT NULL,
capacity            int(3),
PRIMARY KEY (section_ID),
FOREIGN KEY (instructor_ID) REFERENCES Instructor (instructor_ID),
FOREIGN KEY (course_ID) REFERENCES Course (course_ID)   
);

CREATE TABLE Enrollment
(
student_ID          int(6)          UNIQUE,
section_ID          int(8)          UNIQUE,
enroll_date         datetime        NOT NULL,
final_grade         char(1),
PRIMARY KEY (section_ID, student_ID),
FOREIGN KEY (section_ID) REFERENCES sections (section_ID),
FOREIGN KEY (student_ID) REFERENCES student (student_ID)
);


/*Step Three: Insert Rows*/
INSERT INTO Zipcode VALUES
(7024, 'Ft. Lee', 'NJ'),
(7047, 'North Bergen', 'NJ'),
(10005, 'New York', 'NY'),
(10015, 'New York', 'NY'),
(10025, 'New York', 'NY'),
(10035, 'New York', 'NY'),
(11419, 'Richmond Hill', 'NY'),
(11435, 'Jamaica', 'NY');

INSERT INTO Student VALUES
(102, 'Mr.', 'Fred', 'Crocitto', '101-09 120th St.', 718-555-5555, 'Albert Hildegard Co.', 1/22/2007, 11419),
(103, 'Ms.', 'J.', 'Landry', '7435 Boulevard East #45', 201-555-5555, 'Albert Hildegard Co.', 1/22/2007, 7047),
(104, 'Ms.', 'Laetia', 'Enison', '144-61 87th Ave', 718-555-5555, 'Albert Hildegard Co.', 1/22/2007, 11435),
(105, 'Mr.', 'Angel', 'Moskowitz', '320 John St.', 201-555-5555, 'Alex. & Alexander', 1/22/2007, 7024),
(163, 'Ms.', 'Nicole', 'Gillen', '4301 N Ocean #103', 904-555-5555, 'Oil of America Corp.', 2/2/2007, 10025),
(223, 'Mr.', 'Frank', 'Pace', '13 Burlington Dr.', 203-555-5555, 'Board Utilities', 2/8/2007, 10025),
(399, 'Mr.', 'Jerry', 'Abdou', '460 15th St. #4', 718-555-5555, 'Health Mgmt.Systems', 2/23/2007, 10025);

INSERT INTO Course VALUES
(330, 'Network Administration', 1195, 130),
(310, 'Operating Systems', 1195, NULL),
(142, 'Project Management', 1195, 20),
(140, 'Systems Analysis', 1195, 20),
(130, 'Intro to Unix', 1195, 310),
(25, 'Intro to Programming', 1195, 140),
(20, 'Intro to Information Systems', 1195, NULL);

INSERT INTO Instructor VALUES
(101, 'Mr.', 'Fernand', 'Hanks', '100 East 87th', 10015),
(102, 'Mr.', 'Tom', 'Wojick', '518 West 120th', 10025),
(103, 'Ms.', 'Nina', 'Schorin', '210 West 101st', 10025),
(104, 'Mr.', 'Gary', 'Pertez', '34 Sixth Ave', 10035),
(105, 'Ms.', 'Anita', 'Morris', '34 Maiden Lane', 10015),
(106, 'Rev.', 'Todd', 'Smythe', '210 West 101st', 10025),
(107, 'Dr.', 'Marilyn', 'Frantzen', '254 Bleeker', 10005);

INSERT INTO Sections VALUES
(81, 20, 2, 7/24/2007 9:30, 'L210', 103, 15),
(86, 25, 2, 6/10/2007 9:30, 'L210', 107, 15),
(89, 25, 5, 5/15/2007 9:30, 'L509', 103, 25),
(92, 25, 8, 6/13/2007 9:30, 'L509', 106, 25),
(104, 330, 1, 7/14/2007 10:30, 'L511', 104, 25),
(119, 142, 1, 7/14/2007 9:30, 'L211', 103, 25),
(155, 122, 4, 5/4/2007 9:30,  'L210', 107, 15);

INSERT INTO Enrollment VALUES
(102, 86, 1/30/2007, NULL, 'B'),
(102, 89, 1/30/2007, 92,'A'),
(103, 81, 1/30/2007, NULL),
(104, 81, 1/30/2007, NULL, 'A'),
(163, 92, 2/10/2007, NULL),
(223, 104, 2/16/2007, NULL,'C'),
(223, 119, 2/16/2007, NULL);


/*Step Four: Select Statements*/
SELECT * FROM Student;
SELECT * FROM Zipcode;
SELECT * FROM Instructor;
SELECT * FROM Course;
SELECT * FROM Sections;
SELECT * FROM Enrollment;

错误消息确定的问题是日期时间文字,此处:

 INSERT INTO Sections VALUES
 (81, 20, 2, 7/24/2007 9:30, 'L210', 103, 15)
             ^^^^^^^^^^^^^^

要获取分配给日期时间列的值,您可以这样做:

 (81, 20, 2, '2007-07-24 09:30', 'L210', 103, 15)
             ^^^^^^^^^^^^^^^^^^

日期时间文字应该用单引号括起来,并以 'YYYY-MM-DD''YYYY-MM-DD HH:MI:SS'.

等格式表示

(也可以传入十进制数字值。但没有人真正这样做。只需使用正确格式的字符串文字即可。我相信 MySQL 的新版本比早期版本更宽松, 关于月份的两个字符和日期的两个字符的严格性,以及使用破折号以外的定界符。我认为也可以省略日期时间的定界符

我想 MySQL 也会接受这样的东西:

   '20070724093000'

但同样,没有人真正做到这一点。只需以标准 'YYYY-MM-DD HH:MI:SS' 格式提供字符串形式的值。