如何让示例代码工作?错误 1452

How to get Sample code working? Error 1452

我两天前才开始将 mySQL workbench 与 MAMP 一起使用,它正在实现。我不断收到有关无法更新子行和外部约束失败的错误。不过,我非常确定需要外部约束才能将表绑定在一起。

create schema TerryLight717;
use TerryLight717;
CREATE DATABASE UniversityDB;
Use UniversityDB; CREATE TABLE student ( sid INTEGER, 
                       sname VARCHAR(25),
                       sex CHAR(1),
                       age INTEGER,
                       yeir INTEGER,
                       gpa REAL,
                       PRIMARY KEY (sid) );

CREATE TABLE dept ( dname VARCHAR(25),
                    numphds INTEGER,                    
                    PRIMARY KEY (dname) );

CREATE TABLE prof ( pname VARCHAR(25),
                    dname VARCHAR(25),                    
                    PRIMARY KEY (pname),
                    FOREIGN KEY (dname) REFERENCES dept(dname) );

CREATE TABLE course ( cno INTEGER,
                      cname VARCHAR(30),
                      dname VARCHAR(25),
                      PRIMARY KEY (cno, dname),
                      FOREIGN KEY (dname) REFERENCES dept (dname));

CREATE TABLE major ( dname VARCHAR(25),
                     sid INTEGER,
                     PRIMARY KEY (dname, sid),
                     FOREIGN KEY (dname) REFERENCES dept (dname),
                     FOREIGN KEY (sid) REFERENCES student (sid));

CREATE TABLE section ( dname VARCHAR(25),
                       cno INTEGER,
                       sectno INTEGER,
                       pname VARCHAR(25),
                       PRIMARY KEY (dname, cno, sectno),
                       FOREIGN KEY (dname) REFERENCES dept (dname),
                       FOREIGN KEY (cno, dname) REFERENCES course (cno,dname),
                       FOREIGN KEY (pname) REFERENCES prof (pname));

CREATE TABLE enroll ( sid INTEGER,
                      grade float,
                      dname VARCHAR(25),
                      cno INTEGER,
                      sectno INTEGER,
                      PRIMARY KEY (sid, dname, cno, sectno),
                      FOREIGN KEY (sid) REFERENCES student (sid),
                      FOREIGN KEY (dname) REFERENCES dept (dname), 
                      FOREIGN KEY (cno, dname) REFERENCES course (cno,dname),
                      FOREIGN KEY (dname, cno, sectno) REFERENCES section (dname,cno,sectno));

INSERT INTO `student` VALUES
(1, 'Jacobs, T.', 'm', 29, 5, 3.60),
(2, 'Pierson, E.', 'm', 32, 5, 3.50),
(3, 'Zeene, Ben N.', 'm', 21, 5, 3.90),
(4, 'Sulfate, Barry M.', 'm', 19, 2, 2.80),
(5, 'Form, Clara O.', 'f', 18, 1, 3.30),
(6, 'Scott, Kim J.', 'm', 20, 1, 3.80),
(7, 'Sather, Roberto B.', 'm', 22, 4, 2.20),
(8, 'Stanley, Leotha T.', 'm', 21, 3, 3.60),
(9, 'Smith, Joyce A.', 'f', 21, 4, 2.00),
(10, 'Jones, David S.', 'm', 19, 2, 3.50),
(11, 'Paul, Mary W.', 'f', 23, 5, 3.60),
(12, 'Soong, V.', 'f', 24, 5, 3.50),
(13, 'Kellerman, S.', 'f', 21, 3, 2.90),
(14, 'Cheong, R.', 'm', 25, 4, 3.00),
(15, 'Borchart, Sandra L.', 'f', 26, 5, 3.90),
(16, 'Alsberg, David J.', 'm', 25, 5, 3.50),
(17, 'Thorton, James Q.', 'm', 28, 4, 2.70),
(18, 'Gooch', 'm', 26, 1, 1.40),
(19, 'Smith, L.', 'm', 43, 4, 0.70),
(20, 'Korpel, E.', 'f', 19, 3, 3.50),
(21, 'Surk, K.', 'm', 23, 2, 2.50),
(22, 'Emile, R.', 'm', 18, 1, 2.00),
(23, 'Bomber, C.', 'f', 22, 4, 3.20),
(24, 'Carter, Jimmy', 'm', 56, 5, 3.50),
(25, 'Kissinger, Henry', 'm', 58, 5, 3.40),
(26, 'Ford, Gerald', 'm', 60, 5, 3.50),
(27, 'Anderson, P.', 'f', 18, 1, 3.20),
(28, 'Austin, G.', 'm', 25, 5, 3.50),
(29, 'Hamilton, S.', 'm', 21, 3, 2.80),
(30, 'Baker, C.', 'f', 18, 1, 3.50),
(31, 'Andrews, R.', 'm', 19, 2, 2.80),
(32, 'Liu, Huihusan', 'm', 29, 5, 3.90),
(33, 'Chao, Tsechih', 'f', 23, 5, 3.60),
(34, 'Kasten, Norman L.', 'm', 23, 2, 2.50),
(35, 'Mathews, John W.', 'm', 29, 5, 3.60),
(36, 'Burroughs, Susan S.', 'f', 18, 1, 3.00),
(37, 'Dunbar, D.', 'm', 30, 5, 3.40),
(38, 'Auen, B.', 'm', 21, 3, 2.70),
(39, 'Shoemaker, A.', 'f', 22, 4, 3.50),
(40, 'Rosemeyer, S.', 'f', 21, 3, 2.90),
(41, 'Fisher, C.', 'f', 22, 4, 3.50),
(42, 'Trude, T.', 'm', 19, 2, 2.90),
(43, 'Ksar, J.', 'm', 20, 3, 3.40),
(44, 'Moeri, S.', 'f', 20, 4, 3.20),
(45, 'June, Granson', 'f', 18, 1, 3.10),
(46, 'Micheal, Zadicki T.', 'm', 22, 2, 2.70),
(47, 'Roger, Blotter N.', 'm', 21, 3, 1.90),
(48, 'Natividad, A.', 'f', 25, 5, 4.00),
(49, 'Villa-lobos, M.', 'm', 47, 5, 3.70),
(50, 'Moomchi, B.', 'm', 32, 5, 3.50),
(51, 'Jetplane, Leaving O.', 'm', 30, 1, 0.00),
(52, 'Fy, Clara I.', 'f', 18, 2, 2.00),
(53, 'Atny, Mary H.', 'f', 26, 5, 3.80),
(54, 'Maximillian', 'm', 98, 5, 3.00),
(55, 'Glitch, R.', 'm', 19, 1, 2.80),
(56, 'Starry, J.', 'f', 22, 4, 3.30),
(57, 'Hiemerschmitz, A.', 'f', 19, 1, 2.70),
(58, 'Marshmallton', 'm', 20, 3, 3.00),
(59, 'Ziebart, F.', 'm', 22, 4, 1.80),
(60, 'Calcmity, J.', 'f', 23, 3, 2.60),
(61, 'Kennedy, Ed', 'm', 55, 3, 2.30),
(62, 'Moses, A.', 'm', 18, 1, 3.20),
(63, 'Kool, Joseph F.', 'm', 35, 5, 3.70),
(64, 'Fred, Edwin B.', 'm', 80, 5, 4.00),
(65, 'Ripper, Jack T.', 'm', 18, 1, 0.50),
(66, 'Altenhaus, Stuart', 'm', 21, 4, 2.80),
(67, 'Altenhaus, Gloria', 'f', 22, 5, 4.00),
(68, 'Crist, J.', 'm', 23, 4, 3.00),
(69, 'Heilskov, G.', 'm', 23, 4, 2.50),
(70, 'Caucutt, B.', 'm', 24, 5, 3.00),
(71, 'Mark, B.', 'm', 24, 4, 3.60),
(72, 'Barnes, J.', 'm', 45, 5, 2.30),
(73, 'Quarnty, G.', 'f', 20, 2, 4.00),
(74, 'Andrus, J.', 'f', 21, 3, 3.70),
(75, 'Jones, A.', 'f', 23, 5, 3.20),
(76, 'Zorhoff, C.', 'm', 20, 3, 3.00),
(77, 'Paull, Thomas H.', 'm', 23, 4, 2.60),
(78, 'Cool, J.', 'm', 18, 2, 2.60),
(79, 'Evert, Chris', 'f', 21, 4, 3.90),
(80, 'Connors, Jimmy', 'm', 25, 1, 0.20),
(81, 'Smith, Ike Z.', 'm', 33, 1, 1.10),
(82, 'News, Nightly', 'm', 15, 1, 1.90),
(83, 'Jones, Ivan L.', 'm', 55, 5, 3.50),
(84, 'Smith, R.', 'm', 19, 3, 2.70),
(85, 'Mayer, N.', 'f', 21, 5, 3.50),
(86, 'Gonring, J.', 'm', 21, 4, 3.70),
(87, 'Mueller, D.', 'm', 20, 3, 3.30),
(88, 'Bates, M.', 'm', 22, 4, 3.30),
(89, 'Longlastname, A.', 'f', 99, 5, 4.00),
(90, 'Zappa, F.', 'm', 16, 4, 4.00),
(91, 'Ghandi, I.', 'f', 78, 1, 3.50),
(92, 'Kirk, J.', 'm', 34, 5, 2.20),
(93, 'Andermanthenol, K.', 'm', 26, 5, 3.70),
(94, 'Uoiea, Z.', 'f', 19, 2, 3.30),
(95, 'Grzlbltz, Q.', 'm', 43, 5, 2.50),
(96, 'Birch, M.', 'f', 23, 5, 3.50),
(97, 'Morgan, D.', 'm', 18, 1, 3.50),
(98, 'Taylor, R.', 'm', 20, 3, 2.80),
(99, 'Jones, J.', 'f', 21, 1, 1.10),
(100, 'Gringo, C.', 'm', 25, 5, 2.90),
(101, 'Davis, Scott P.', 'm', 19, 3, 3.70),
(102, 'Bates, Michael L.', 'm', 22, 4, 3.40),
(103, 'Kaisler, Janet M.', 'f', 21, 4, 3.50),
(104, 'Baskett, Wayse T.', 'm', 23, 3, 2.10);

INSERT INTO dept VALUES
('Chemical Engineering',32),
('Civil Engineering',   88),
('Computer Sciences',   47),
('Industrial Engineering',  41),
('Mathematics', 129),
('Sanitary Engineering' ,3);

Insert into Prof Values
("Brian, C.",   "Computer Sciences"),
("Brown, S.",   "Civil Engineering"),
("Bucket, T.",  "Sanitary Engineering"),
("Clark, E.",   "Civil Engineering"),
("Edison, L.",  "Chemical Engineering"),
("Jones, J.",   "Computer Sciences"),
("Randolph, B.", "Civil Engineering"),
("Robinson, T.", "Mathematics"),
("Smith, S.",   "Industrial Engineering"),
("Walter, A.",  "Industrial Engineering");



INSERT INTO course (cno, cname, dname) VALUES (302, "Intro to Programming","Computer Sciences");
INSERT INTO course (cno, cname, dname) VALUES (310, "Thermodynamics",   "Chemical Engineering");
INSERT INTO course (cno, cname, dname) VALUES (310, "Intro to Garbage", "Sanitary Engineering");
INSERT INTO course (cno, cname, dname) VALUES (365, "City Planning",    "Civil Engineering");
INSERT INTO course (cno, cname, dname) VALUES (375, "Highway Engineering",  "Civil Engineering");
INSERT INTO course (cno, cname, dname) VALUES (461, "College Geometry 1",   "Mathematics");
INSERT INTO course (cno, cname, dname) VALUES (462, "College Geometry 2",   "Mathematics");
INSERT INTO course (cno, cname, dname) VALUES (467, "Intro to Data Structures", "Computer Sciences");
INSERT INTO course (cno, cname, dname) VALUES (514, "Manpower Utilization", "Industrial Engineering");
INSERT INTO course (cno, cname, dname) VALUES (561, "Advanced City Planning",   "Civil Engineering");
INSERT INTO course (cno, cname, dname) VALUES (561, "Advanced Garbage Collection5", "Sanitary Engineering");
INSERT INTO course (cno, cname, dname) VALUES (701, "Compiler Construction",    "Computer Sciences");
INSERT INTO course (cno, cname, dname) VALUES (726, "Nonlinear Programming",    "Computer Sciences");


INSERT INTO section (dname, cno, sectno, pname) VALUES("Chemical Engineering",  310,    1,  "Edison, L.");

INSERT INTO section (dname, cno, sectno, pname) VALUES("Civil Engineering", 365,    1,  "Randolph, B.");
INSERT INTO section (dname, cno, sectno, pname) VALUES("Civil Engineering", 375,    1,  "Brown, S.");
INSERT INTO section (dname, cno, sectno, pname) VALUES("Civil Engineering", 561,    1,  "Randolph, B.");

INSERT INTO section (dname, cno, sectno, pname) VALUES("Computer Sciences", 302,    1,  "Jones, J.");
INSERT INTO section (dname, cno, sectno, pname) VALUES("Computer Sciences", 302,    2,  "Smith, S.");
INSERT INTO section (dname, cno, sectno, pname) VALUES("Computer Sciences", 467,    1,  "Jones, J.");
INSERT INTO section (dname, cno, sectno, pname) VALUES("Computer Sciences", 701,    1,  "Clark, E.");
INSERT INTO section (dname, cno, sectno, pname) VALUES("Computer Sciences", 726,    1,  "Brian, C.");

INSERT INTO section (dname, cno, sectno, pname) VALUES("Industrial Engineering",    514,    1,  "Walter, A.");

INSERT INTO section (dname, cno, sectno, pname) VALUES("Mathematics",   461,    1,  "Robinson, T.");
INSERT INTO section (dname, cno, sectno, pname) VALUES("Mathematics",   462,    1,  "Robinson, T.");

INSERT INTO section (dname, cno, sectno, pname) VALUES("Sanitary Engineering",  561,    1,  "Bucket, T.");




INSERT INTO major (dname, sid) VALUES("Mathematics", 0);

INSERT INTO major (dname, sid) VALUES("Mathematics", 1);
INSERT INTO major (dname, sid) VALUES("Computer Sciences",  1);
INSERT INTO enroll VALUES(1,    3.00,   "Chemical Engineering", 310,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  2);
INSERT INTO major (dname, sid) VALUES("Mathematics",    2);
INSERT INTO enroll VALUES(2 ,3.00,  "Computer Sciences",    302,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  3);
INSERT INTO major (dname, sid) VALUES("Mathematics",    3);
INSERT INTO enroll VALUES(3,    3.50,   "Civil Engineering",    375,    1);

INSERT INTO major (dname, sid) VALUES("Sanitary Engineering",   4);
INSERT INTO major (dname, sid) VALUES("Computer Sciences",  4);
INSERT INTO enroll VALUES(4,    4.00,   "Mathematics",  461,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  5);
INSERT INTO enroll VALUES(5,    3.00,   "Industrial Engineering",   514,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  6);
INSERT INTO enroll VALUES(6,    3.50,   "Computer Sciences",    302,    2);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  7);
INSERT INTO enroll VALUES(7,    4.00,   "Computer Sciences",    302,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  8);
INSERT INTO enroll VALUES(8,    4.00,   "Computer Sciences",    302,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  9);
INSERT INTO enroll VALUES(9,    3.00,   "Civil Engineering",    375,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  10);
INSERT INTO major (dname, sid) VALUES("Computer Sciences",  10);
INSERT INTO enroll VALUES(10,   2.00,   "Computer Sciences",    302,    1);


INSERT INTO major (dname, sid) VALUES("Computer Sciences",  11);
INSERT INTO enroll VALUES(11,   3.00,   "Computer Sciences",    302,    2);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  12);
INSERT INTO enroll VALUES(12,   2.50,   "Computer Sciences",    302,    2);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  13);
INSERT INTO enroll VALUES(13,   2.50,   "Computer Sciences",    302,    2);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  14);
INSERT INTO enroll VALUES(14,   2.50,   "Mathematics",  462,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  15);
INSERT INTO enroll VALUES(15,   3.00,   "Chemical Engineering", 310,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  16);
INSERT INTO enroll VALUES(16,   3.00,   "Computer Sciences",    467,    1);
INSERT INTO enroll VALUES(16,   3.00,   "Computer Sciences",    701,    1);


INSERT INTO major (dname, sid) VALUES("Computer Sciences",  17);
INSERT INTO enroll VALUES(17,   3.00,   "Mathematics",  461,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  18);
INSERT INTO enroll VALUES(18,   2.00,   "Civil Engineering",    375,    1);
INSERT INTO enroll VALUES(18,   3.50,   "Mathematics",  461,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  19);
INSERT INTO enroll VALUES(19,   3.50,   "Mathematics",  461,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  20);
INSERT INTO enroll VALUES(20,   2.50,   "Computer Sciences",    302,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  21);
INSERT INTO enroll VALUES(21,   3.00,   "Computer Sciences",    467,    1);
INSERT INTO enroll VALUES(21,   3.50,   "Industrial Engineering",   514,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  22);
INSERT INTO enroll VALUES(22,   3.00,   "Computer Sciences",    302,    1);
INSERT INTO enroll VALUES(22,   3.00,   "Computer Sciences",    467,    1);


INSERT INTO major (dname, sid) VALUES("Computer Sciences",  23);
INSERT INTO enroll VALUES(23,   4.00,   "Civil Engineering",    561,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  24);
INSERT INTO enroll VALUES(24,   4.00,   "Computer Sciences",    302,    2);


INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   25);
INSERT INTO enroll VALUES(25,   3.50,   "Computer Sciences",    302,    1);

INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   26);
INSERT INTO enroll VALUES(26,   3.50,   "Mathematics",  462,    1);

INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   27);
INSERT INTO enroll VALUES(27,   2.50,   "Industrial Engineering",   514,    1);

INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   28);
INSERT INTO enroll VALUES(28,   3.00,   "Mathematics",  461,    1);


INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   29);
INSERT INTO enroll VALUES(29,   3.00,   "Civil Engineering",    365,    1);
INSERT INTO enroll VALUES(29,   3.00,   "Civil Engineering",    375,    1);
INSERT INTO enroll VALUES(29,   3.00,   "Civil Engineering",    561,    1);

INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   30);
INSERT INTO enroll VALUES(30,   4.00,   "Computer Sciences",    467,    1);

INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   31);

INSERT INTO enroll VALUES(31,   3.50,   "Computer Sciences",    302,    1);

INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   32);
INSERT INTO enroll VALUES(32,   2.00,   "Civil Engineering",    561,    1);

INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   33);
INSERT INTO enroll VALUES(33,   2.00,   "Civil Engineering",    365,    1);
INSERT INTO enroll VALUES(33,   3.00,   "Computer Sciences",    726,    1);

INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   34);
INSERT INTO enroll VALUES(34,   1.00,   "Civil Engineering",    561,    1);


INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   35);
INSERT INTO enroll VALUES(35,   3.00,   "Mathematics",  461,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  36);
INSERT INTO enroll VALUES(36,   3.00,   "Civil Engineering",    375,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  37);
INSERT INTO enroll VALUES(37,   3.00,   "Mathematics",  462,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  38);
INSERT INTO enroll VALUES(38,   3.00,   "Computer Sciences",    302,    2);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  39);
INSERT INTO enroll VALUES(39,   3.00,   "Computer Sciences",    302,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  40);
INSERT INTO enroll VALUES(40,   3.50,   "Mathematics",  462,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  41);
INSERT INTO enroll VALUES(41,   3.00,   "Computer Sciences",    701,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  42);
INSERT INTO enroll VALUES(42,   3.50,   "Computer Sciences",    701,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  43);
INSERT INTO enroll VALUES(43,   2.50,   "Computer Sciences",    467,    1);


INSERT INTO major (dname, sid) VALUES("Civil Engineering",  44);
INSERT INTO enroll VALUES(44,   4.00,   "Computer Sciences",    726,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  45);
INSERT INTO enroll VALUES(45,   3.00,   "Chemical Engineering", 310,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  46);
INSERT INTO enroll VALUES(46,   4.00,   "Computer Sciences",    726,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  47);
INSERT INTO enroll VALUES(47,   1.00,   "Civil Engineering",    365,    1);
INSERT INTO enroll VALUES(47,   0.00,   "Civil Engineering",    561,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  48);

INSERT INTO enroll VALUES(48,   1.50,   "Civil Engineering",    561,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  49);
INSERT INTO enroll VALUES(49,   3.50,   "Chemical Engineering", 310,    1);
INSERT INTO enroll VALUES(49,   3.50,   "Industrial Engineering",   514,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  50);
INSERT INTO enroll VALUES(50,   4.00,   "Industrial Engineering",   514,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  51);
INSERT INTO enroll VALUES(51,   3.00,   "Computer Sciences",    726,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  52);
INSERT INTO enroll VALUES(52,   1.00,   "Computer Sciences",    302,    1);
INSERT INTO enroll VALUES(52,   4.00,   "Computer Sciences",    467,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  53);
INSERT INTO enroll VALUES(53,   4.00,   "Mathematics",  462,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  54);
INSERT INTO enroll VALUES(54,   3.00,   "Civil Engineering",    375,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  55);
INSERT INTO enroll VALUES(55,   2.50,   "Mathematics",  461,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  56);
INSERT INTO enroll VALUES(56,   2.50,   "Chemical Engineering", 310,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  57);
INSERT INTO enroll VALUES(57,   3.50,   "Computer Sciences",    467,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  58);
INSERT INTO enroll VALUES(58,   2.00,   "Industrial Engineering",   514,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  59);
INSERT INTO enroll VALUES(59,   3.50,   "Mathematics",  462,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  60);
INSERT INTO enroll VALUES(60,   2.50,   "Civil Engineering",    561,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  61);
INSERT INTO enroll VALUES(61,   3.50,   "Civil Engineering",    561,    1);
INSERT INTO enroll VALUES(61,   2.00,   "Computer Sciences",    726,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  62);
INSERT INTO enroll VALUES(62,   2.50,   "Computer Sciences",    726,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  63);
INSERT INTO enroll VALUES(63,   2.50,   "Computer Sciences",    701,    1);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 64);
INSERT INTO enroll VALUES(64,   4.00,   "Civil Engineering",    561,    1);
INSERT INTO enroll VALUES(64,   3.50,   "Computer Sciences",    726,    1);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 65);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 66);
INSERT INTO enroll VALUES(66,   1.50,   "Civil Engineering",    365,    1);
INSERT INTO enroll VALUES(66,   4.00,   "Civil Engineering",    375,    1);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 67);
INSERT INTO enroll VALUES(67,   3.50,   "Computer Sciences",    467,    1);
INSERT INTO enroll VALUES(67,   4.00,   "Computer Sciences",    701,    1);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 68);
INSERT INTO enroll VALUES(68,   3.50,   "Computer Sciences",    726,    1);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 69);
INSERT INTO enroll VALUES(69,   3.50,   "Computer Sciences",    302,    2);
INSERT INTO enroll VALUES(69,   2.00,   "Computer Sciences",    467,    1);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 70);
INSERT INTO enroll VALUES(70,   3.50,   "Civil Engineering",    561,    1);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 71);
INSERT INTO enroll VALUES(71,   2.50,   "Computer Sciences",    701,    1);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 72);
INSERT INTO enroll VALUES(72,   3.50,   "Computer Sciences",    726,    1);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 73);
INSERT INTO enroll VALUES(73,   3.00,   "Civil Engineering",    375,    1);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 74);
INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 75);
INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 76);
INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 77);
INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 78);
INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 79);
INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 80);
INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 81);
INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 82);
INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 83);
INSERT INTO major (dname, sid) VALUES("Mathematics",    84);
INSERT INTO major (dname, sid) VALUES("Mathematics",    85);
INSERT INTO major (dname, sid) VALUES("Mathematics",    86);
INSERT INTO major (dname, sid) VALUES("Mathematics",    87);
INSERT INTO major (dname, sid) VALUES("Mathematics",    88);
INSERT INTO major (dname, sid) VALUES("Mathematics",    89);
INSERT INTO major (dname, sid) VALUES("Mathematics",    90);
INSERT INTO major (dname, sid) VALUES("Mathematics",    91);
INSERT INTO major (dname, sid) VALUES("Mathematics",    92);
INSERT INTO major (dname, sid) VALUES("Mathematics",    93);
INSERT INTO major (dname, sid) VALUES("Mathematics",    94);
INSERT INTO major (dname, sid) VALUES("Mathematics",    95);


INSERT INTO major (dname, sid) VALUES("Mathematics",    96);
INSERT INTO enroll VALUES(96,   4.00,   "Civil Engineering",    365,    1);
INSERT INTO enroll VALUES(96,   3.00,   "Civil Engineering",    561,    1);

INSERT INTO major (dname, sid) VALUES("Mathematics",    97);
INSERT INTO enroll VALUES(97,   3.00,   "Industrial Engineering",   514,    1);

INSERT INTO major (dname, sid) VALUES("Mathematics",    98);
INSERT INTO enroll VALUES(98,   4.00,   "Industrial Engineering",   514,    1);

INSERT INTO major (dname, sid) VALUES("Mathematics",    99);
INSERT INTO enroll VALUES(99,   3.50,   "Computer Sciences",    701,    1);

INSERT INTO enroll VALUES(100,  2.00,   "Computer Sciences",    726,    1);
INSERT INTO enroll VALUES(101,  4.00,   "Mathematics",  462, 1);
INSERT INTO enroll VALUES(102,  3.50,   "Mathematics",  461,    1);
INSERT INTO enroll VALUES(103,  4.00,   "Computer Sciences",    701,    1);
INSERT INTO enroll VALUES(104,  2.80,   "Computer Sciences",    302,    2);
INSERT INTO enroll VALUES(104,  2.60,   "Sanitary Engineering", 561,    1);

我想我明白问题所在了。 prof.pname 的值都有前导 space,而 section.pname 的值没有。

我被教导不要将 varchar 用于关键字段,也不要将名称或任何其他可能因官僚主义行为而改变的数据(例如名称)用于关键值.遵循这条规则往往会大大减少头痛。