搭建一个简易的成绩管理系统的数据库
题目描述
我的实现:
CREATE DATABASE gradesystem;
USE gradesystem;
CREATE TABLE student
(
sid INT(12) PRIMARY KEY auto_increment,
sname VARCHAR(20),
gender VARCHAR(12)
);
CREATE TABLE course
(
cid INT(12) PRIMARY KEY auto_increment,
cname VARCHAR(20)
);
CREATE TABLE mark
(
mid INT(12) PRIMARY KEY auto_increment,
sid INT(12),
cid INT(12),
score INT(12),
FOREIGN KEY(sid) references student(sid),
FOREIGN KEY(cid) references course(cid)
);
insert into student (sid, sname,gender) values(1, 'Tom', 'male'), (2, 'Jack','male'), (3,'Rose','female');
insert into course (cid, cname) values(1, 'math'), (2, 'physics'), (3,'chemistry');
insert into mark (mid,sid,cid, score) 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);
另一个代码实例:
CREATE DATABASE mysql_shiyan;
use mysql_shiyan;
CREATE TABLE department
(
dpt_name CHAR(20) NOT NULL,
people_num INT(10) DEFAULT '10',
CONSTRAINT dpt_pk PRIMARY KEY (dpt_name)
);
CREATE TABLE employee
(
id INT(10) PRIMARY KEY,
name CHAR(20),
age INT(10),
salary INT(10) NOT NULL,
phone INT(12) NOT NULL,
in_dpt CHAR(20) NOT NULL,
UNIQUE (phone),
CONSTRAINT emp_fk FOREIGN KEY (in_dpt) REFERENCES department(dpt_name)
);
CREATE TABLE project
(
proj_num INT(10) NOT NULL,
proj_name CHAR(20) NOT NULL,
start_date DATE NOT NULL,
end_date DATE DEFAULT '2015-04-01',
of_dpt CHAR(20) REFERENCES department(dpt_name),
CONSTRAINT proj_pk PRIMARY KEY (proj_num,proj_name)
);