MySQL数据库day03

一、表的三范式

    1、没有重复的字段且都具有原子性不可再拆分

    2、表中的所有属性都与主键相关 (主键 非空且唯一)

    3、确保每列属性都与主键列直接相关,而不是间接相关

    三范式是在不断使用数据库的过程中总结的三项准则,遵循它能最大效率地使用数据库中的资源

    学生表

        学号 姓名 性别 身份证号 班级编号

        create table Student(

            id int primary key,

            name varchar(20) not null,

            sex char default 'w',

            id_card char(18) unique,

            class_id int,

            foreign key(class_id) references Class(id) on delete/update cascade,

            ...

        );

    成绩表

        学号 语文 数学 英语

        create table Grade(

            id int primary key,

            c_grade float check(c_grade>=0 and c_grade<=100),

            m_grade float check(m_grade>=0 and m_grade<=100),

            e_grade float check(e_grade>=0 and e_grade<=100),

            foreign key(id) references Student(id) on delete/update cascade,

            ...

        );

    班级表

        班级编号 教室 班主任 语文老师 数学老师 英语老师

        create table Class(

            id int primary key,

            room_id int not null unique,

            class_teacher int,

            c_teacher int,

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值