数据库介绍:(参考链接:https://www.shiyanlou.com/courses/9/learning/?id=2769)
搭建一个数据库来管理学生的成绩,数据库内有三张表,分别用来记录学生信息,课程信息和成绩信息;学生表(学生id,学生姓名,学生性别),课程信息(课程id,课程名字),成绩表(成绩id,学生id,课程id,分数);
1 $ sudo service mysql start 2 ##要注意行号自增,键值约束; 3 $ mysql -u root -p 4 5 mysql> CREATE DATABASE gradesystem; 6 7 mysql> use gradesystem 8 9 mysql> CREATE TABLE student( 10 -> sid int NOT NULL AUTO_INCREMENT, 11 -> sname varchar(20) NOT NULL, 12 -> gender varchar(10) NOT NULL, 13 -> PRIMARY KEY(sid) 14 -> ); 15 16 mysql> CREATE TABLE course( 17 -> cid int NOT NULL AUTO_INCREMENT, 18 -> cname varchar(20) NOT NULL, 19 -> PRIMARY KEY(cid) 20 -> ); 21 22 mysql> CREATE TABLE mark( 23 -> mid int NOT NULL AUTO_INCREMENT, 24 -> sid int NOT NULL, 25 -> cid int NOT NULL, 26 -> score int NOT NULL, 27 -> PRIMARY KEY(mid), 28 -> FOREIGN KEY(sid) REFERENCES student(sid), 29 -> FOREIGN KEY(cid) REFERENCES course(cid) 30 -> ); 31 32 mysql> INSERT INTO student VALUES(1,'Tom','male'),(2,'Jack','male'),(3,'Rose','female'); 33 34 mysql> INSERT INTO course VALUES(1,'math'),(2,'physics'),(3,'chemistry'); 35 36 mysql> INSERT INTO mark VALUES(1,1,1,80),(2,2,1,85),(3,3,1,90),(4,1,2,60),(5,2,2,90),(6,3,2,75),(7,1,3,95),(8,2,3,75),(9,3,3,85);