数据库第二次作业

1.教师表 teacher

字段名

数据类型

长度(字节数)

是否可null

默认值

主、外键

其他约束

备注信息

NO

CHAR

4

主键

教师号

NAME

VARCHAR

10

教师姓名

PROF

VARCHAR

20

assistant

职称

SAL

INT

2

工资

COMM

SMALLINT

2

岗位津贴

 

 

mysql> create table teacher(
    -> no char(4) primary key comment"教师号",
    -> name varchar(10) not null comment"教师姓名",
    -> prof varchar(20) default"assistant" comment"职称"not null,
    -> sal int(2) not null comment"工资");

2.学生表 student

字段名

数据类型

长度(字节数)

是否可null

默认值

主、外键

其他约束

备注信息

NO

CHAR

4

主键

学生号

NAME

VARCHAR

10

学生姓名

AGE

TINYINT

1

年龄

DEPT

VARCHAR

20

computer

系名

 

mysql> create table 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

字段名

数据类型

长度(字节数)

是否可null

默认值

主、外键

其他约束

备注信息

NO

CHAR

4

主键

课程号

NAME

VARCHAR

20

唯一

课程名

CLASS_HOURS

INT

2

45

课时数

mysql> create table course(
    -> no char(4) primary key comment"课程号",
    -> name varchar(20) not null unique comment"课程名",
    -> class_hours int(2) default 45 comment"课时数");

 

4.授课表 school_teaching

字段名

数据类型

长度(字节数)

是否可null

默认值

主、外键

其他约束

备注信息

ID

INT

4

主键

自动增加

序号

COURSE_NO

CHAR

4

外键course(no)

课程号

TEACHER_NO

CHAR

4

外键teacher(no)

教师号

WEEK

INT

2

15

周数

CLASS_NUM

VARCHAR

10

教室号

 

mysql> create table 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_teacher_no foreign key (teacher_no) references teacher(no)
    -> );

 

 5.成绩表 grade

字段名

数据类型

长度(字节数)

是否可null

默认值

主、外键

其他约束

备注信息

STUDENT_NO

CHAR

4

主键

学生号

COURSE_NO

CHAR

4

主键

课程号

SCORE

FLOAT

60

成绩

 

mysql> create table 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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值