创建一个表,可以记录客户及购物情况

一.有一个商店的数据,记录客户及购物情况,有以下三个表组成:
商品goods(商品编号goods_id,商品名goods_name, 单价unitprice, 商品类别category, 供应商provider)
客户customer(客户号customer_id,姓名name,住址address,邮箱email,性别sex,身份证card_id)
购买purchase(购买订单号order_id,客户号customer_ id,商品号goods_ id,购买数量nums)
要求:每个表的主外键,客户的姓名不能为空值 ,邮箱不能重复 、客户的性别(男,女)
创建库

create database if not exists shops charset=utf8 collate utf8_bin engine innodb;  //创建库

1.关于商品的表

create table if not exists goods(           //创建商品的表
goods_id int primary key auto_increment comment '品牌号',
goods_name varchar(20) not null comment'商品名称',
unitprice float(6,2) not null default 0 comment'商品单价',
category varchar(10) not null comment'商品类别'
);

2.关于客户的表

create table if not exists customer(    
customer_id int primary key auto_increment comment'客户编号',
name varchar(10) not null comment'客户姓名',
email varchar(30) unique comment'邮箱',
sex enum('男','女') default '男'comment'客户性别',
card_id char(18) unique comment'客户身份证'
);

3.关于购买的表

create table if not exists purchase(
order_id int primary key auto_increment comment'购买订单',
customer_id int comment '客户编号',
goods_id  int comment'商品编号',
nums int not null comment'购买数量',
foreign key (goods_id) references goods(goods_id),
foreign key(customer_id) references customer (customer_id)
);

三张表的结构:
在这里插入图片描述
在这里插入图片描述

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值