不知道为什么代码没运行一次,sc表就会出现一组重复的数据啊啊w(゚Д゚)w
CREATE TABLE Student
(sno CHAR(3) CONSTRAINT pk_sno PRIMARY KEY,
sname VARCHAR(20) UNIQUE,
age INT NOT NULL
);
CREATE TABLE course
(cno CHAR(3) PRIMARY KEY,
cname VARCHAR(30),
credit INT CHECK(credit BETWEEN 1 AND 4),
teacher VARCHAR(10)
);
CREATE TABLE sc
(sno CHAR(3) ,
cno CHAR(3) ,
score INT CHECK( score BETWEEN 1 AND 100),
PRIMARY KEY(sno,cno),
FOREIGN KEY(sno) REFERENCES student(sno),
FOREIGN KEY (cno) REFERENCES course(cno)
);
INSERT INTO student
VALUES ('s1','王刚','19'),('s2','李晓','18');
INSERT INTO course
VALUES ('c1','c语言','3','李老师'),('c2','java','2','张老师');
INSERT IGNORE INTO sc(sno,cno,score)
VALUES ('s1','c1','99'),('s1','c2','93'),('s2','c1','56');
SELECT * FROM sc;