MYSQL数据库系统第2次实验 数据表的创建

实验目的:

  1. 熟悉数据表约束;
  2. 熟练掌握创建数据表。
    实验设备及器材:
    PC,mysql 等

实验内容:
1.创建数据库teaching;

mysql>create database if not exists teaching;

2.选择数据库teaching;

mysql> use teaching;

3.在teaching数据库中根据以下要求创建以下6张表:

表student
在这里插入图片描述

mysql> create table if not exists student(
    -> studentno char(11) not null comment'学号',
    -> sname char(8) not null comment'姓名',
    -> sex enum('男','女') default '男' comment'性别',
    -> brithdate date not null comment'出生日期',
    -> entrance int(3) null comment'入学成绩',
    -> phone varchar(12) not null comment'电话',
    -> Email varchar(20) not null comment'电子邮箱',
    -> primary key(studentno),
    -> unique (Email)
    -> )charset='utf8';

表course
在这里插入图片描述
在这里插入图片描述

mysql> create table if not exists course(
    -> courseno char(6) not null comment'课程编号',
    -> cname char(6) not null comment'课程名称',
    -> type char(8) not null comment'类别',
    -> period int(2) not null comment'总学时',
    -> exp int (2) not null comment'实验学时',
    -> term int(2) not null comment '开学学期',
    -> primary key(courseno)
    -> )charset='utf8';

表score
在这里插入图片描述

mysql> create table if not exists score(
    -> studentno char(11) not null comment'学号',
    -> courseno char(6) not null comment'课程编号',
    -> daily float(3,1) default '0.0' comment'平时成绩',
    -> final float(3,1) default '0.0' comment'期末成绩',
    -> primary key(studentno,courseno)
    -> )charset='utf8';

表teacher
在这里插入图片描述

mysql> create table if not exists teacher(
    -> teacherno char(6) not null comment'教师编号',
    -> tname char(8) not null comment'教师姓名',
    -> major char(10) not null comment'专业',
    -> prof char(10) not null comment'职称',
    -> department char(16) not null comment'部门',
    -> primary key(teacherno)
    -> )charset='utf8';

表teach_course
在这里插入图片描述

mysql> create table if not exists teach_course(
    -> teacherno char(6) not null comment'教师编号',
    -> courseno char(6) not null comment'课程编号',
    -> primary key(teacherno,courseno)
    -> )charset='utf8';

表sc
在这里插入图片描述

mysql> create table if not exists sc(
    -> sc_no int(6) not null auto_increment comment'选课编号',
    -> student char(11) not null comment'学生编号',
    -> courseno char(6) not null comment'课程编号',
    -> teacherno char(6) not null comment'教师编号',
    -> sc_time timestamp not null default now() comment'选课时间',
    -> primary key(sc_no)
    -> )charset='utf8';

  • 4
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值