MySql教程

06 MySQL_数据冗余

本文主要是介绍06 MySQL_数据冗余,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

数据冗余--拆分表

  • 如果表设计不合理,可能会出现大量的重复数据,这种现象被称为数据冗余,通过拆分表的形式可以解决此问题

    • 保存集团总部下财务部里面的财务A部的张三工资8000 年龄18

    • 保存集团总部下研发部的李四工资800 年龄75

    • 部门 员工姓名 工资 年龄

      create table t_emp(id int primary auto_increment,name varchar(10),sal int ,age int,dept int);
    
      create table t_dept(id int primary auto_incermen ,name varchar(10),parent_id int);
    
  • 插入数据,先插入部门数据,再插入员工表数据

    insert into  t_dept values(null,'集团总部',null),(null,'财务部',1),(null,'财务A部',2),(null,'研发部',1);
    
    insert into  t_emp valuse(null,'张三',8000,18,3),(null,'李四',800,75,4);
    
  • 练习:

    1. 保存家电分类下洗衣机分类下的海尔洗衣机价格2300,库存38

    2. 保存办公用品下,笔分类的晨光圆珠笔 价格5,库存100;

       - create table commodity(id int primary key auto_increment, name varchar(10),price int,库存, int,category int);
       - create table kinds (id int primary key auto_increment,name varchar(10),parent_id int);
       - insert into kinds values (null,'家电',null),(null,'洗衣机',1),(null,'办公用品',null),(null,'笔',3);
         - insert into commodity values (null,'海尔洗衣机',2300,38);
    
这篇关于06 MySQL_数据冗余的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!