1.题目
学生选课系统
1. 创建学生选课系统
2. 切换数据库
3. 创建学生表 TbStudent
主键stuid ,姓名stuname,
性别stusex,生日stubirth,电话stutel,住址stuaddr
照片stuphoto(以二进制存)
4. 创建课程表TbCourse
主键cosid, 班级名称cosname,学分coscredit,课程描述cosintro
5. 学生选课记录表TbSC
主键scid,学生外键sid ,班级外键cid,创建日期scdate, 分数score
2.创建学生数据库
create database student;
use student;
-- 创建学生表
create table tbstudent
(
stuid integer not null,
stuname varchar(20) not null,
stusex bit default 1,
stubirth datetime not null,
stutel varchar(11),
stuaddr varchar(255),
stuphoto longblob,
primary key (stuid)
);
-- 如果TBCourse已经存在就删除它
drop table if exists TbCourse;
-- 创建课程表
create table TbCourse
(
cosid integer not null,
cosname varchar(50) not null,
coscredit tinyint not null,
cosintro varchar(255)
);
-- 给课程表指定主键
alter table TbCourse add constraint pk_course primary key (cosid);
-- 创建学生选课记录表
create table tbSC
(
scid integer primary key auto_increment,
sid integer not null,
cid integer,
scdate datetime not null,
score float
);
-- 给表TBSC添加外键约束
alter table TbSC add constraint fk_sid foreign key (sid) references TbStudent (
stuid) on delete cascade on update cascade;
alter table TbSC add constraint fk_cid foreign key (cid) references TBCourse (
cosid) on delete set null on update cascade;