0
点赞
收藏
分享

微信扫一扫

数据库 MYSQL第二次课堂作业

椰果玩安卓 2022-03-12 阅读 52

创建一个表为教师表 teacher的数据表:

 代码:create table  qiufaqing_teacher(
    -> NO char(4) primary key comment"教师号",
    -> NAME varchar(10) not null comment"教师姓名",
    -> PROF varchar(20) not null default"assistant" comment"职称",
    -> SAL int(2) not null comment"工资",
    -> COMM smallint(2) comment"岗位津贴"
    -> );

结果:

 

2.创建一个表名为学生表的数据表(student)

 

代码:create table qiufaqing_student(
    -> NO char(4) primary key comment"学生号",
    -> NAME varchar(10) not null comment"学生姓名",
    -> AGE tinyint(1) not null comment"年龄",
    -> DEPT varchar(20) not null default"computer" comment"系名"
    -> );

结果:

 

 3.创建一个表名为课程表的数据表(course)

 代码:mysql> create table qingfaqing_school_teaching(
    -> ID int(4) primary key auto_increment comment "序号",
    -> COURSE_NO char(4) not unll comment "课程号",
    -> TEACHER_NO char(4) not unll comment "教室号",
    -> WEEK int(2) default"15" comment "周数",
    -> CLASS_NUM varchar(10) not unll comment "教室号"
    -> constraint fk_COURSE_NO foreign key(TEACHER_NO) references qiufaqing_course(NO)
    -> );

结果:

  4.创建一个名为授课表的数据表(school teaching)

 代码:

create table zhushaobin_school_teaching(
    -> ID int(4) primary key auto_increment comment"序号",
    -> COURSE_NO char(4) not null comment"课程号",
    -> TEACHER_NO char(4) not null comment"教室号",
    -> WEEK int(2) default"15" comment"周数",
    -> CLASS_NUM varchar(10) not null comment"教室号",
    -> constraint fk_COURSE_NO foreign key(COURSE_NO) references zhushaobin_course(NO),
    -> constraint fk_TEACHER_NO foreign key(TEACHER_NO) references zhushaobin_course(NO)
    -> );
结果:

 5.创建一个名为成绩表的数据表(grade)

代码:create table zhushaobin_grade(
    -> STUDENT_NO char(4) not null comment"学生号",
    -> COURSE_NO char(4) not null comment"课程号",
    -> SCORE float not null default"60" comment"成绩",
    -> primary key(STUDENT_NO,COURSE_NO)
    -> );
结果:

 

举报

相关推荐

0 条评论