目录
4.创建卖家信息表“seller_姓名全拼”,表中字段信息如下:
5.创建买家信息表“buyer_姓名全拼”,表中字段信息如下:
6.创建地址表“address_姓名全拼”,表中字段信息如下:
7.创建产品种类表“product_type_姓名全拼”,表中字段信息如下:
8.创建产品表“product_姓名全拼”,表中字段信息如下:
10.创建订单详情表“order_detail_姓名全拼”,表中字段信息如下:
1.user_zhongjinlin表所有字段批量插入用户表数据
2.seller_zhongjinlin表所有字段批量插入卖家信息表数据
3.buyer_zhongjinlin表指定字段批量插入买家信息表数据
4.address_zhongjinlin表指定字段批量插入地址表数据
5.product_type_zhongjinlin表所有字段批量插入产品种类表数据
6.product_zhongjinlin表指定字段插入产品表数据
7.product_zhongjinlin所有字段插入产品表数据
8.product_zhongjinlin表指定字段插入产品表数据
9.product_zhongjinlin表所有字段插入产品表数据
11.order_zhongjinlin表订单表指定字段插入数据
12.order_detail_zhongjinlin表订单详情表指定字段插入数据
13.修改订单详情表中O_20201102_00001订单P_20190102_00002产品的采购数量为1
14.查看O_20201102_00001订单的订单编号、产品编号、库存数量、采购数量、采购后数量(库存数量-采购数量)、产品单价、折后单价
16.根据订单号分组查看订单号、订单总价(sum(采购数量*产品单价))、实付款(sum(采购数量*折扣单价))
17.根据上述代码计算出的值修改订单表中O_20201102_00001订单的总价、实付款数据
4.查看O_20201102_00002订单的订单编号、产品编号、库存数量、采购数量、采购后数量(库存数量-采购数量)、产品单价、折后单价
6.根据订单号分组查看订单总价(sum(采购数量*产品单价))、实付款(sum(采购数量*折扣单价))
7.根据上述代码计算出的值修改订单表中O_20201102_00002订单的总价、实付款数据
12.修改订单详情表中O_20201102_00002订单P_20190203_00002产品的折后单价为180
13.修改订单详情表中O_20201102_00002订单P_20190203_00001产品的折后单价为200
14.根据订单号分组查看实付款(sum(采购数量*折扣单价))
15.根据上述代码计算出的值修改订单表中O_20201102_00002订单的实付款数据
18.查看O_20201102_00002订单的订单编号、店铺名称、买家昵称、详细地址、产品名称、采购数量、折后价格
2.创建买家信息视图“view_buyer_info_姓名全拼”查看上述内容
5.创建产品信息视图“view_product_ info_姓名全拼”查看上述内容
7.查看产品信息视图中已经有过订单销售记录的产品数据(子查询 in)
8.查看订单编号、店铺名称、买家昵称、详细地址、产品名称、采购数量、折后价格
9.创建订单信息视图“view_order_ info_姓名全拼”查看上述内容
1.备份所有数据库,文件名为“all_姓名全拼.sql”(截两张图 命令+文件)
2.备份电子商城数据库,文件名为“mall_姓名全拼.sql”(截两张图 命令+文件)
任务一、二
-
安装并配置MySQL
1.打开控制台
2.登录MySQL
-
数据库、表的基本操作
1.创建电子商城数据库“mall_姓名全拼”
create database mall_zhongjinlin;
2.使用电子商城数据库
use mall_zhongjinlin;
3.创建用户表“user_姓名全拼”,表中字段信息如下:
字段名 |
数据类型 |
长度 |
主、外键 |
其他约束 |
备注信息 |
char |
11 |
主键 |
注册手机号 |
||
username |
varchar |
20 |
非空,唯一 |
用户名 |
|
password |
varchar |
20 |
非空 |
密码 |
|
question |
text |
非空 |
找回密码问题 |
||
answer |
text |
非空 |
找回密码问题答案 |
create table user_zhongjinlin(
-> phone char(11) primary key comment "注册手机号",
-> username varchar(20) not null unique comment "用户名",
-> password varchar(20) not null comment "密码",
-> question text not null comment "找回密码问题",
-> answer text not null comment "找回密码问题答案"
-> );
4.创建卖家信息表“seller_姓名全拼”,表中字段信息如下:
字段名 |
数据类型 |
长度 |
主、外键 |
其他约束 |
备注信息 |
id |
char |
16 |
主键 |
卖家ID(S_DATE_XXXXX) |
|
phone |
char |
11 |
外键(user.phone) |
非空,唯一 |
注册手机号 |
open_date |
date |
非空 |
开业时间 |
||
name |
varchar |
50 |
非空 |
店铺名称 |
|
nickname |
varchar |
30 |
非空 |
掌柜昵称 |
create table seller_zhongjinlin(
-> id char(16) primary key comment "卖家ID(S_DATE_XXXXX)",
-> phone char(11) not null unique comment "注册手机号",
-> open_date date not null comment "开业时间",
-> name varchar(50) not null comment "店铺名称",
-> nickname varchar(30) not null comment "掌柜昵称",
-> constraint fk_phone foreign key(phone) references user_zhongjinlin(phone)
-> );
5.创建买家信息表“buyer_姓名全拼”,表中字段信息如下:
字段名 |
数据类型 |
长度 |
主、外键 |
其他约束 |
备注信息 |
id |
char |
16 |
主键 |
买家ID(B_DATE_XXXXX) |
|
phone |
char |
11 |
外键(user.phone) |
非空,唯一 |
注册手机号 |
nickname |
varchar |
30 |
非空 |
买家昵称 |
|
gender |
enum(“miss”,”mr”) |
默认miss |
性别 |
||
height |
int |
3 |
身高cm |
||
weight |
double |
体重kg |
create table buyer_zhongjinlin(
-> id char(16) primary key comment "卖家ID(S_DATE_XXXXX)",
-> phone char(11) not null unique comment "注册手机号",
-> nickname varchar(30) not null comment "买家昵称",
-> gender enum("miss","mr") default "miss" comment "性别",
-> height int(3) comment "身高cm",
-> weight double comment "体重kg",
-> constraint fk_phone2 foreign key(phone) references user_zhongjinlin(phone)
-> );
6.创建地址表“address_姓名全拼”,表中字段信息如下:
字段名 |
数据类型 |
长度 |
主、外键 |
其他约束 |
备注信息 |
id |
char |
16 |
主键 |
地址ID (A_DATE_XXXXX) |
|
buyer_id |
char |
16 |
外键(buyer.id) |
非空 |
买家ID |
contact_phone |
char |
11 |
非空 |
收货人联系方式 |
|
detail_address |
text |
非空 |
详细地址 |
||
is_default |
enum(“yes”,”no”) |
默认 no |
是否默认地址 |
create table address_zhongjinlin(
-> id char(16) primary key comment "地址ID (A_DATE_XXXXX)",
-> buyer_id char(16) not null comment "买家ID",
-> contact_phone char(11) not null comment "收货人联系方式",
-> detail_address text not null comment "详细地址",
-> is_default enum("yes","no") default "no" comment "是否默认地址",
-> constraint fk_buyer_id foreign key(buyer_id) references buyer_zhongjinlin(id)
-> );
7.创建产品种类表“product_type_姓名全拼”,表中字段信息如下:
字段名 |
数据类型 |
长度 |
主、外键 |
其他约束 |
备注信息 |
code |
char |
6 |
主键 |
产品种类编码(TXXXXX) |
|
name |
varchar |
30 |
非空 |
产品种类名称 |
create table product_type_zhongjinlin(
-> code char(6) primary key comment "产品种类编码(TXXXXX)",
-> name varchar(30) not null comment "产品种类名称"
-> );
8.创建产品表“product_姓名全拼”,表中字段信息如下:
字段名 |
数据类型 |
长度 |
主、外键 |
其他约束 |
备注信息 |
id |
char |
16 |
主键 |
产品编号(P_DATE_XXXXX) |
|
seller_id |
char |
16 |
外键(seller.id)< |