mysql08 表结构搭建--练习

 搭建的表结构要求说明:
mysql08  表结构搭建--练习mysql08  表结构搭建--练习

挑战参考代码

$ sudo service mysql start

$ mysql -u root

mysql> CREATE DATABASE gradesystem;

mysql> use gradesystem

mysql> CREATE TABLE student(
    -> sid int NOT NULL AUTO_INCREMENT,
    -> sname varchar(20) NOT NULL,
    -> gender varchar(10) NOT NULL,
    -> PRIMARY KEY(sid)
    -> );

mysql> CREATE TABLE course(
    -> cid int NOT NULL AUTO_INCREMENT,
    -> cname varchar(20) NOT NULL,
    -> PRIMARY KEY(cid)
    -> );

mysql> CREATE TABLE mark(
    -> mid int NOT NULL AUTO_INCREMENT,
    -> sid int NOT NULL,
    -> cid int NOT NULL,
    -> score int NOT NULL,
    -> PRIMARY KEY(mid),
    -> FOREIGN KEY(sid) REFERENCES student(sid),
    -> FOREIGN KEY(cid) REFERENCES course(cid)
    -> );

mysql> INSERT INTO student VALUES(1,‘Tom‘,‘male‘),(2,‘Jack‘,‘male‘),(3,‘Rose‘,‘female‘);

mysql> INSERT INTO course VALUES(1,‘math‘),(2,‘physics‘),(3,‘chemistry‘);

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);

 ----说明:本材料采用在线实验室,只为了学习记录,无其他用途。

相关推荐