python学习站 /第四周mysql数据库
阅读主题
正文字体
字体大小

05.homework

本节2332字2025-04-15 11:11:40
-- 学生表:id、姓名、性别、出生日期、所属学院				 #student	
-- 教师表:id、名字、职称、性别、出生日期、所属学院 	     #teacher
-- 课程表:id、名称、开课时间、学分、讲师					 #kecheng		
-- 学院表:id、名称、简介                                     #coollege
-- 选课记录表:id、学生、课程、选课时间、考试成绩			 #xuanke

create	table if not exists `t_coollege`(
	`col_id` int not null unique auto_increment comment '学院ID',
    `col_name` varchar(20) not null comment '学院名称',
    `col_intro` varchar(200) comment '学院介绍',
    primary key(`col_id`)
    );
    
create table if not exists `t_students`(
	`stu_id` int not null unique auto_increment comment '学生ID',
    `stu_name` varchar(10) not null comment '学生姓名',
    `stu_birth` timestamp ,
    `stu_sex` tinyint default 1 comment '性别',
    `sti_coollege` int comment '学生所在学院的ID编号',
    constraint fk_students_college foreign key (`sti_coollege`) references `t_coollege`(`col_id`),
    primary key(`stu_id`)
);

create table if not exists `teachers`(
	`tea_id` int not null unique auto_increment comment '老师id',
    `tea_name` varchar(10) not null comment '老师姓名',
    `tea_zhicheng` varchar(10) comment '职称',
    `tea_sex` tinyint default 1 comment '性别',
    `tea_birth` timestamp ,
    `tea_coollege` int comment '所属学院',
     constraint fk_tea_college foreign key (`tea_coollege`) references `t_coollege`(`col_id`),
     primary key(`tea_id`)
);



create table if not exists `kecheng`(
	`k_id` int not null unique auto_increment comment '课程ID',
    `k_name` varchar(10) not null comment '课程名称',
    `k_time` timestamp ,
    `k_xuefen` decimal(2,1) default 1 comment '学分',
    `k_teacher` int comment '讲师',
    constraint fk_kecheng_teacher foreign key (`k_teacher`) references `teachers`(`tea_id`),
    primary key(`k_id`)
);

    
create table if not exists `t_xuanke`(
	`x_id` int not null unique auto_increment comment '选课ID',
    `x_stu` int comment '学生id外键',
    `x_kecheng` int comment '课程ID外键',
    `x_time` timestamp, 
    `x_chengji` int comment '考试成绩外键',
	constraint fk_xuanke_stu foreign key (`x_stu`) references `t_students`(`stu_id`),
	constraint fk_xuanke_kecheng foreign key (`x_kecheng`) references `kecheng`(`k_id`),
	primary key(`x_id`)
   );


网友评论

相关作品