第二天ci项目规划 数据库设计

商品 + 用户 + 订单

数据库设计思想和方法

  1. 关于商品品牌 ,分类 ,属性 如何表示 用一个字段 还是再设计一张表 品牌和商品 是一种信息 还是两种信息 一张表一般只保存一种信息
  2. 品牌和商品能否独立分开 二者生命周期是否一致
  3. 表与表之间的关系
    1. 一对一 A中一条记录 在B中对应的最多只有一条 反之亦然
    2. 一对多 A中一条记录在b中对应N条 反之只有一条
    3. 多对多 A中记录在b中对应的有N条 反之有m条
    4. 分类的层级关系
      1. 使用path 自引用
    5. 商品属性信息保存 商品与属性独立存储 attribute表属性与商品表关系 多对多 简化为两个一对多关系 goods_attr另attribute有type需要一张表
    6. 订单设计 一个订单 可包含多种商品 一个商品 可能有多个订单 订单和商品之间多对多 应该在添加一张表表示他们之间关联联系

      drop table if exists attr;

    drop table if exists brand;

    drop table if exists category;

    drop table if exists goods;

    drop table if exists goods_attr;

    drop table if exists goods_type;

    drop table if exists orde_rinfo;

    drop table if exists "order";

    drop table if exists user;

    /==============================================================/
    /* Table: attr /
    /
    ==============================================================*/
    create table attr
    (
    attr_id integer not null auto_increment,
    attr_name varbinary(10) not null,
    input_type integer not null,
    "values" varchar(10) not null,
    type_id integer not null,
    primary key (attr_id)
    )
    engine = MYISAM;

    /==============================================================/
    /* Table: brand /
    /
    ==============================================================*/
    create table brand
    (
    brand_id integer not null auto_increment,
    brand_name varchar(10),
    primary key (brand_id)
    )
    engine = MYISAM;

    /==============================================================/
    /* Table: category /
    /
    ==============================================================*/
    create table category
    (
    cat_id integer not null auto_increment,
    cat_name varchar(10) not null,
    parent_id integer not null,
    primary key (cat_id)
    )
    engine = MYISAM;

    /==============================================================/
    /* Table: goods /
    /
    ==============================================================*/
    create table goods
    (
    goods_id integer not null auto_increment,
    goods_name varchar(10) not null,
    market_price decimal(10,2) not null,
    shop_price decimal(10,2) not null,
    goods_img char(10) not null,
    goods_number integer not null,
    goods_desc text(100) not null,
    brand_id integer not null,
    cat_id integer not null,
    primary key (goods_id)
    )
    engine = MYISAM;

    /==============================================================/
    /* Table: goods_attr /
    /
    ==============================================================*/
    create table goods_attr
    (
    rec_id integer not null auto_increment,
    goods_id integer not null,
    attr_id integer not null,
    value char(10) not null,
    primary key (rec_id)
    )
    engine = MYISAM;

    /==============================================================/
    /* Table: goods_type /
    /
    ==============================================================*/
    create table goods_type
    (
    type_id integer not null auto_increment,
    type_name varbinary(30) not null,
    primary key (type_id)
    )
    engine = MYISAM;

    /==============================================================/
    /* Table: orde_rinfo /
    /
    ==============================================================*/
    create table orde_rinfo
    (
    red_id integer not null auto_increment,
    order_id integer not null,
    goods_id integer not null,
    primary key (red_id)
    )
    engine = MYISAM;

    /==============================================================/
    /* Table: "order" /
    /
    ==============================================================*/
    create table "order"
    (
    order_id integer not null,
    user_id integer,
    order_sn char(10) not null,
    order_tome integer not null,
    total_price decimal(10,2) not null,
    primary key (order_id)
    )
    engine = MYISAM;

    /==============================================================/
    /* Table: user /
    /
    ==============================================================*/
    create table user
    (
    user_id integer not null auto_increment,
    name varchar(10) not null,
    password char(10) not null,
    email varchar(10) not null,
    primary key (user_id)
    )
    engine = MYISAM;

    alter table attr add constraint FK_Reference_5 foreign key (type_id)
    references goods_type (type_id) on delete restrict on update restrict;

    alter table goods add constraint FK_Reference_1 foreign key (brand_id)
    references brand (brand_id) on delete restrict on update restrict;

    alter table goods add constraint FK_Reference_2 foreign key (cat_id)
    references category (cat_id) on delete restrict on update restrict;

    alter table goods_attr add constraint FK_Reference_3 foreign key (goods_id)
    references goods (goods_id) on delete restrict on update restrict;

    alter table goods_attr add constraint FK_Reference_4 foreign key (attr_id)
    references attr (attr_id) on delete restrict on update restrict;

    alter table orde_rinfo add constraint FK_Reference_7 foreign key (goods_id)
    references goods (goods_id) on delete restrict on update restrict;

    alter table orde_rinfo add constraint FK_Reference_8 foreign key (order_id)
    references "order" (order_id) on delete restrict on update restrict;

    alter table "order" add constraint FK_Reference_6 foreign key (user_id)
    references user (user_id) on delete restrict on update restrict;

第二天ci项目规划 数据库设计的更多相关文章

  1. 第二天ci项目规划 前后台分离

    第二天ci项目规划 前后台分离 1/31/2016 2:40:26 PM 前后台 表面上看前后台不同网站 但是数据是他们之间的联系要完成结构完整项目 设计好前后台 基于mvc框架 前后台那些地方不同 ...

  2. HNU_团队项目_数据库设计感想_个人感想

    数据库设计感想  个人的一点心得体会 最重要的放在最前面——讨论开会时的123经验 开会前对会议目的及方式要有所考虑: 不要随意无目的开会: 遵守时间,控制会议时间长度: 会议主持人要维持会议只需,有 ...

  3. Django 博客项目01 数据库设计与验证码校验+Ajax登录

    数据库设计 from django.db import models from django.contrib.auth.models import AbstractUser class UserInf ...

  4. [ci]项目规划-后续

      几个方面来写   1,搭建gitlab 配邮箱 域名等使之好用 2,搭建jenkins –yum,安装常见插件 3,搭建sonar,汉化 4,安装sonar-scanner   0,实现sonar ...

  5. MySQL数据分析-(5)数据库设计之ER模型

    大家好,我是jacky,很高兴跟大家分享本课时的内容,从本节课开始,就开始了我们第二章的学习,第一章我们抛出了若干问题,从第二章开始往后,都是解决问题的一个过程: 第一章的案例中,我们拿手机销售公司举 ...

  6. 15套java互联网架构师、高并发、集群、负载均衡、高可用、数据库设计、缓存、性能优化、大型分布式 项目实战视频教程

    * { font-family: "Microsoft YaHei" !important } h1 { color: #FF0 } 15套java架构师.集群.高可用.高可扩 展 ...

  7. 常见电商项目的数据库表设计(MySQL版)

    转自:https://cloud.tencent.com/developer/article/1164332 简介: 目的: 电商常用功能模块的数据库设计 常见问题的数据库解决方案 环境: MySQL ...

  8. 小福bbs—项目系统设计与数据库设计

    这个作业属于哪个课程 班级链接 这个作业要求在哪里 作业要求的链接 团队名称 小福bbs 这个作业的目标 实现对校园论坛软件的制作,使其能够发布帖子,查看信息等 作业的正文 小福bbs--项目需求分析 ...

  9. T-MAX—项目系统设计与数据库设计

    团队作业第四次-项目系统设计与数据库设计 这个作业属于哪个课程 2019秋福大软件工程实践Z班 这个作业要求在哪里 团队作业第四次-项目系统设计与数据库设计 团队名称 T-MAX 这个作业的目标 在开 ...

随机推荐

  1. C和指针 第十五章 错误报告perror和exit

    15.1 错误报告 perror 任何一种程序都存在出错的可能,包括系统的函数库,当出现错误时,系统提示发生错误,标准库函数在一个外部整型变量中保存错误代码,然后把错误代码传给用户程序,提示错误原因. ...

  2. IP变化,SVN和数据库的修改

    最近公司换了运营商,将启用新的IP地址,将以前项目的端口映射处理好之外,还需要切换SVN的地址. 项目开发中有可能要修改SVN的IP地址,entries文件里面包含svn服务器的地址信息.每个文件夹都 ...

  3. EXCEL 2010学习笔记 —— 数据透视表

    今天整理一下EXCEL2010 数据透视表的课程笔记,数据透视表可以对多组数据进行统计和整理,是一种基本的数据可视化工具. 记录6个方面的总结: 1.创建数据透视表 2.更改数据透视表的汇总方式 3. ...

  4. 键盘按钮keyCode大全

    字母和数字键的键码值(keyCode) 按键 键码 按键 键码 按键 键码 按键 键码 A 65 J 74 S 83 1 49 B 66 K 75 T 84 2 50 C 67 L 76 U 85 3 ...

  5. Menu与ActionBar的爱恨情仇

    最近在开发一款音乐播放器,在开发过程中遇到了一点小麻烦,通过android API搞清楚了Menu与ActionBar的爱恨情仇,写了个小Demo祭奠一下那些年我们陷进去的坑,有不对的地方请大神们批评 ...

  6. Python全栈【异常处理】

    Python全栈[异常处理] 本节内容: 1.异常处理 2.什么时候用异常处理 异常处理 1.异常处理: 异常就是程序运行时发生错误的信号,异常处理是在编程过程中为了增加友好性,在程序出现bug时一般 ...

  7. axure rp8.0 序列号,亲测可以用

    转载自:https://zhidao.baidu.com/question/428326076480233092.html aaa 2GQrt5XHYY7SBK/4b22Gm4Dh8alaR0/0k3 ...

  8. Echarts 3.19 制作常用的图形 非静态

    最近阿里内部使用的 图表也向外开放了 而百度就好像更有良心一点,Echarts 早就开放了 . 自己学Echarts的时候走了很多的弯路,毕竟谁让自己菜呢,多撞几次南墙才晓得疼 才知道学习方法,新手上 ...

  9. 修改Sqlserver实例默认排序规则

    1.将sqlserver安装盘加载到虚拟光驱,这里加载到F:盘跟目录 2.cmd进入命令 3.输入命令: F:/Setup /QUIET /ACTION=REBUILDDATABASE /INSTAN ...

  10. C语言 指针小结

    指针 -->指针变量 类型名 *变量名 int *point1; char *point2; 注意:*p可以直接使用,它代表指针p指向的变量,*p可以当做被指向的变量使用!~~~~ 一个变量的地 ...