数据库第十四次作业--- 电子商城项目

  • 安装并配置MySQL

  1. 打开控制台
  2. 登录MySQL
  • 数据库、表的基本操作

  1. 创建电子商城数据库“mall_姓名全拼”
  2. 使用电子商城数据库
  3. 创建用户表“user_姓名全拼”,表中字段信息如下:

 代码:

create table user_chengweiqiang(
     phone char(11) comment"注册手机号" primary key,
    -> username varchar(20) comment"用户名" not null unique,
    -> password varchar(20) comment"密码" not null,
    -> question text comment"找回密码问题" not null,
    -> answer text comment"找回密码问题答案" not null);

字段名

数据类型

长度

主、外键

其他约束

备注信息

phone

char

11

主键

注册手机号

username

varchar

20

非空,唯一

用户名

password

varchar

20

非空

密码

question

text

非空

找回密码问题

answer

text

非空

找回密码问题答案

  1. 创建卖家信息表“seller_姓名全拼”,表中字段信息如下:
  2. create table seller_chengweiqiang(
        -> id char(16) comment"卖家id" primary key,
        -> phone char(11) comment"注册手机号" not null unique,
        -> open_date date comment"开业时间" not null,
        -> name varchar(50) comment"店铺名称" not null,
        -> nickname varchar(30) comment"掌柜名称" not null,
        -> constraint fk_phone foreign key(phone) references user_chengweiqiang(phone));

字段名

数据类型

长度

主、外键

其他约束

备注信息

id

char

16

主键

卖家ID(S_DATE_XXXXX)

phone

char

11

外键(user.phone)

非空,唯一

注册手机号

open_date

date

非空

开业时间

name

varchar

50

非空

店铺名称

nickname

varchar

30

非空

掌柜昵称

  1. 创建买家信息表“buyer_姓名全拼”,表中字段信息如下:
  2. create table buyer_chengweiqiang(
        -> id char(16) comment"买家ID(B_DATE_XXXX" primary key ,
        -> phone char(11) comment"注册手机号" not null unique,
        -> nickname varchar(30) comment"买家昵称" not null,
        -> gender enum("miss","mr") comment"性别" default"miss",
        -> height int(3) comment"身高",
        -> weight double comment"体重",
        -> constraint fk1_phone foreign key(phone) references user_chengweiqiang(phone));

字段名

数据类型

长度

主、外键

其他约束

备注信息

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

  1. 创建地址表“address_姓名全拼”,表中字段信息如下:
create table address_chengweiqiang(
    -> id char(16) comment"地址" primary key,
    -> buyer_id char(16) comment"买家id" not null,                   ,
    -> contact_phone char(11) comment"收货人联系方式" not null ,
    -> detail_address text comment"详细地址" not null,
    -> is_default enum("yes","no") comment"是 否默认地址" default"no",
    -> constraint fk2_buyer_id foreign key(buyer_id) references buyer_chengweiqiang(id));

 

字段名

数据类型

长度

主、外键

其他约束

备注信息

id

char

16

主键

mall_chengweiqiangXXXX)

buyer_id

char

16

外键(buyer.id)

非空

买家ID

contact_phone

char

11

非空

收货人联系方式

detail_address

text

非空

详细地址

is_default

enum(“yes”,”no”)

默认 no

是否默认地址

  1. 创建产品种类表“product_type_姓名全拼”,表中字段信息如下:
  • create table product_chengweiqiang(
        -> code char(6) comment"产品种类编码(TXXXXX)" primary key,
        -> name varchar(30) comment"产品种类名称" not null);

字段名

数据类型

长度

主、外键

其他约束

备注信息

code

char

6

主键

产品种类编码(TXXXXX)

name

varchar

30

非空

产品种类名称
  1. 创建产品表“product_姓名全拼”,表中字段信息如下:
  2. create table product_chengweiqiang(
        -> id char(16) comment"产品编号(P_DATE_XXXXX)" primary key,
        -> seller_id char(16) comment"卖家id" not null,
        -> type_id char(6) comment"产品种类编码" not null,
        -> name varchar(100) comment"产品名称" not  null ,
        -> priture text comment"产品展示图",
        -> unit_price double comment"单价" not null,
        -> quantity int(10) comment"库存数量" default"100",
        -> constraint fk3_seller_id foreign key (seller_id) references seller_chengweiqiang(id),
        -> constraint fk4_type_id foreign key (type_id) references product_type(code));

字段名

数据类型

长度

主、外键

其他约束

备注信息

id

char

16

主键

产品编号(P_DATE_XXXXX)

seller_id

char

16

外键(seller.id)

非空

卖家ID

type_id

char

6

外键(product_type.code)

非空

产品种类编码

name

varchar

100

非空

产品名称

picture

text

产品展示图

unit_price

double

非空

单价

quantity

int

10

默认 100

库存数量

  1. 创建订单表“order_姓名全拼”,表中字段信息如下:

字段名

数据类型

长度

主、外键

其他约束

备注信息

id

char

16

主键

订单编号(O_DATE_XXXXX)

seller_id

char

16

外键(seller.id)

非空

卖家ID

buyer_id

char

16

外键(buyer.id)

非空

买家ID

address_id

char

16

外键(address.id)

非空

地址ID

total_price

double

默认0

总价

actrual_payment

double

默认0

实付款

  1. 创建订单详情表“order_detail_姓名全拼”,表中字段信息如下:
  2. create table order_detail(
        -> id int(10) primary key auto_increment,
        -> order_id char(16) comment"订单编号" not null ,
        -> product_id char(16) comment"铲平编号" not null,
        -> purchase_quantity int(3) default"1" comment"采购数量",
        -> discount_unit_price double comment"产品折后价格" not null,
        -> constraint fk12_order_id foreign key(order_id) references order_chengweiqiang(id),
        -> constraint fk34_product_id foreign key(product_id) references product_chengweiqiang(id));

字段名

数据类型

长度

主、外键

其他约束

备注信息

id

int

10

主键

自增

order_id

char

16

外键(order.id)

非空

订单编号

product_id

char

16

外键(product.id)

非空

产品编号

purchase_quantity

int

3

默认1

采购数量

discount_unit_price

double

非空

产品折后价

插入数据

  1. 所有字段批量插入用户表数据
  2. insert into user_chengweiqiang values
        -> ("13812345678","anne","annnepassword","favorite book","harry potter"),("18212345678","frank","Frankpassword","Favorite song","lonely"),("13212345678","alan","Alanpassword","First love","carry"),("13112345678","peter","Peterpassword","Who is your father","jack");

phone

username

password

question

answer

13812345678

anne

annnepassword

favorite book

harry potter

18212345678

frank

Frankpassword

Favorite song

lonely

13212345678

alan

Alanpassword

First love

carry

13112345678

peter

Peterpassword

Who is your father

  1. 所有字段批量插入卖家信息表数据
  2. insert into seller_chengweiqiang values
        -> ("S_20200703_00001","13812345678","2020-07-03","ledin","ledin"),("S_20201030_00001","18212345678","2020-10-30","hla","hla");

id

phone

open_date

name

nickname

S_20200703_00001

13812345678

2020-07-03

ledin

ledin

S_20201030_00001

18212345678

2020-10-30

hla

hla

  1. 指定字段批量插入买家信息表数据
  2. insert into buyer_chengweiqiang(id,phone,nickname,height,weight) values
        -> ("B_20200422_00001","13212345678","funny shop","168","52"),("B_20200911_00001","13112345678","cool girl","165","47");

id

phone

nickname

height

weight

B_20200422_00001

13212345678

funny shop

168

52

B_20200911_00001

13112345678

cool girl

165

47

  1. 指定字段批量插入地址表数据
  2.  insert into address_chengweiqiang(id,buyer_id,contact_phone,detail_address) values
        -> ("A_20201103_00004","B_20200422_00001","13212345678","gray street"),("A_20201103_00005","B_20200422_00001","13212345678","funny street"),("A_20201103_00006","B_20200422_00001","13212345678","frank street"),("A_20201103_00007","B_20200911_00001","13112345678","rock street");

id

buyer_id

contact_phone

detail_address

A_20201103_00004

B_20200422_00001

13212345678

gray street

A_20201103_00005

B_20200422_00001

13212345678

funny street

A_20201103_00006

B_20200422_00001

13212345678

frank street

A_20201103_00007

B_20200911_00001

13112345678

rock street

  1. 所有字段批量插入产品种类表数据
  2. insert into product_type values
        -> ("T00001","coat"),
        -> ("T00002","shirt"),
        -> ("T00003","shorts"),
        -> ("T00004","pants"),
        -> ("T00005","jeans"),
        -> ("T00006","polo");

code

name

T00001

coat

T00002

shirt

T00003

shorts

T00004

pants

T00005

jeans

T00006

polo

  1. 指定字段插入产品表数据
  2. insert product_chengweiqiang(id,seller_id,type_id,name,priture,unit_price) values
        -> ("P_20190102_00001","S_20200703_00001","T00003","blue shorts","p123.jpg","168.8");

id

seller_id

type_id

name

picture

unit_price

P_20190102_00001

S_20200703_00001

T00003

blue shorts

p123.jpg

168.8

  1. 所有字段插入产品表数据

 

insert product_chengweiqiang values
    -> ("P_20190102_00002","S_20200703_00001","T00001","coat","coat1.jpg","62.2","43");

id

seller_id

type_id

name

picture

unit_price

quantity

P_20190102_00002

S_20200703_00001

T00001

coat

coat1.jpg

62.2

43

  1. 指定字段插入产品表数据

 insert product_chengweiqiang(id,seller_id,type_id,name,unit_price) values
    -> ("P_20190203_00001","S_20201030_00001","T00006","black polo","239.9");

id

seller_id

type_id

name

unit_price

P_20190203_00001

S_20201030_00001

T00006

black polo

239.9

  1. 所有字段插入产品表数据
insert product_chengweiqiang values
    -> ("P_20190203_00002","S_20201030_00001","T00005","jeans","12.jpg","198.8","23");

id

seller_id

type_id

name

picture

unit_price

quantity

P_20190203_00002

S_20201030_00001

T00005

jeans

12.jpg

198.8

23

  1. 查看产品表所有字段数据
  2. 订单表指定字段插入数据

insert into order_chengweiqiang(id,seller_id,buyer_id,address_id) values
    -> ("O_20201102_00001","S_20200703_00001","B_20200422_00001","A_20201103_00004");

id

seller_id

buyer_id

address_id

O_20201102_00001

S_20200703_00001

B_20200422_00001

A_20201103_00004

  1. 订单详情表指定字段插入数据
  2. insert into order_detail(order_id,product_id,purchase_quantity,discount_unit_price) values
        -> ("O_20201102_00001","P_20190102_00001","1","150"),
        -> ("O_20201102_00001","P_20190102_00002","2","40");

order_id

product_id

purchase_quantity

discount_unit_price

O_20201102_00001

P_20190102_00001

1

150

O_20201102_00001

P_20190102_00002

2

40

id

seller_id

buyer_id

address_id

O_20201102_00002

S_20201030_00001

B_20200911_00001

A_20201103_00007

order_id

product_id

purchase_quantity

discount_unit_price

O_20201102_00002

P_20190203_00001

1

230

O_20201102_00002

P_20190203_00002

2

190

查看订单信息视图中采购数量不为1的数

  1. 修改订单详情表中O_20201102_00001订单P_20190102_00002产品的采购数量为1
  2. update order_detail set purchase_quantity="1" where product_id="P_20190102_00002";

    查看O_20201102_00001订单的订单编号、产品编号、库存数量、采购数量、采购后数量(库存数量-采购数量)、产品单价、折后单价
  3. select a.order_id,a.product_id,b.quantity ,b.quantity-a.purchase_quantity 采购后数量,
        -> b.unit_price,a.discount_unit_price from order_detail a inner join product_chengweiqiang b
        -> on a.product_id = b.id;

  4. 修改产品表中库存数量为采购后数量
  5. update product_chengweiqiang set quantity="99" where id="P_20190102_00001";
    update product_chengweiqiang set quantity="42" where id="P_20190102_00002";

  6. 根据订单号分组查看订单号、订单总价(sum(采购数量*产品单价))、实付款(sum(采购数量*折扣单价))
  7. select a.order_id,a.purchase_quantity*b.unit_price 订单总价格,a.purchase_quantity*discount_unit_price 实付款 from order_detail a inner join product_chengweiqiang b on a.product_id = b.id;
  8. 根据上述代码计算出的值修改订单表中O_20201102_00001订单的总价、实付款数据
  9. update order_chengweiqiang set total_proce = "239.9",actrual_payment="230" where id="O_20201102_00002";
  10. 查看O_20201102_00001订单的订单编号、店铺名称、买家昵称、详细地址、产品名称、采购数量、折后价
  11. select a.id,b.name,c.nickname,d.detail_address,e.name,f.purchase_quantity,f.discount_unit_price from order_chengweiqiang a inner join seller_chengweiqiang b on a.seller_id = b.id
        -> inner join buyer_chengweiqiang c on a.buyer_id = c.id
        -> inner join address_chengweiqiang d on a.address_id = d.id
        -> inner join product_chengweiqiang e on b.id = e.seller_id
        -> inner join order_detail f on a.id=f.order_id
        -> where f.order_id ="O_20201102_00001";

  12. 任务四、使用事务操作表中数据

  13. 开启事务
  14.  start transaction;

  15. 订单表指定字段插入数据
  16. insert into order_chengweiqiang(id ,seller_id ,buyer_id ,address_id ) values
        -> ("O_20201102_00002","S_20201030_00001","B_20200911_00001","A_20201103_00007");

  17. 订单详情表指定字段插入数
  18. insert into order_detail (order_id,product_id ,purchase_quantity,discount_unit_price)values
        -> ("O_20201102_00002","P_20190203_00001","1","230"),
        -> ("O_20201102_00002","P_20190203_00002","2","190");

  19. 查看O_20201102_00002订单的订单编号、产品编号、库存数量、采购数量、采购后数量(库存数量-采购数量)、产品单价、折后单价
  20. select a.order_id,a.product_id,a.purchase_quantity,b.quantity,b.quantity-a.purchase_quantity 采购后数量,b.unit_price,a.discount_unit_price from order_detail a inner join product_chengweiqiang b on a.product_id = b.id;

  21. 修改产品表中库存数量为采购后数量
  22.  update product_chengweiqiang set quantity = "99" where id ="P_20190102_00001" or id="P_20190203_00001";
    
    update product_chengweiqiang set quantity = "42" where id ="P_20190203_00002";
    
     update product_chengweiqiang set quantity = "21" where id ="P_20190203_00002";

  23. 根据订单号分组查看订单总价(sum(采购数量*产品单价))、实付款(sum(采购数量*折扣单价))
  24. select a.order_id,a.purchase_quantity*b.unit_price 订单总价格,a.purchase_quantity*discount_unit_price 实付款 from order_detail a inner join product_chengweiqiang b on a.product_id = b.id;

  25. 根据上述代码计算出的值修改订单表中O_20201102_00002订单的总价、实付款数据
  26. update order_chengweiqiang set total_proce = "239.9",actrual_payment="230" where id="O_20201102_00002";

  27. 查看订单表所有字段数据
  28. 查看订单详情表所有字段数据
  29. 提交事务
  30. 开启事务
  31. 修改订单详情表中O_20201102_00002订单P_20190203_00002产品的折后单价为180
  32. update order_detail set discount_unit_price="180" where order_id="O_20201102_00002" and product_id="P_20190203_00002";

  33. 修改订单详情表中O_20201102_00002订单P_20190203_00001产品的折后单价为200
  34. update order_detail set discount_unit_price="200" where order_id="O_20201102_00002" and product_id="P_20190203_00001";

  35. 根据订单号分组查看实付款(sum(采购数量*折扣单价))
  36. select a.order_id,a.purchase_quantity*discount_unit_price 实付款 from order_detail a inner join product_chengweiqiang b on a.product_id = b.id;

  37. 根据上述代码计算出的值修改订单表中O_20201102_00002订单的实付款数据
  38. update order_chengweiqiang set actrual_payment="360" where id="O_20201102_00002";

  39. 查看订单详情表所有字段数据
  40. 回滚事务
  41. 查看O_20201102_00002订单的订单编号、店铺名称、买家昵称、详细地址、产品名称、采购数量、折后价格
  42. select a.id,b.name,c.nickname,d.detail_address,e.name,f.purchase_quantity,f.discount_unit_price from order_chengweiqiang a inner join seller_chengweiqiang b on a.seller_id = b.id
         inner join buyer_chengweiqiang c on a.buyer_id = c.id
         inner join address_chengweiqiang d on a.address_id = d.id
         inner join product_chengweiqiang e on b.id = e.seller_id
         inner join order_detail f on a.id=f.order_id
         where f.order_id ="O_20201102_00002";

  43. 查看买家昵称、性别、联系方式、详细地址、是否默认地址
  44. select a.nickname,a.gender,a.phone,b.detail_address,b.is_default from buyer_chengweiqiang a inner join address_chengweiqiang b on a.id=b.buyer_id;

  45. 创建买家信息视图“view_buyer_info_姓名全拼”查看上述内容
  46. create view view_buyer_info_chengweiqiang as select a.nickname,a.gender,a.phone,b.detail_address,b.is_default from buyer_chengweiqiang a inner join address_chengweiqiang b on a.id=b.buyer_id;

  47. 查看买家信息视图买家昵称含有“h”的数据
  48. select * from view_buyer_info_chengweiqiang where nickname like "%h%";

  49. 查看产品种类编码、产品种类名称、产品名称、单价、库存
  50. select a.code,a.name,b.name,b.unit_price,b.quantity from product_type a
        -> inner join product_chengweiqiang b on a.code=b.type_id;

  51. 创建产品信息视图“view_product_ info_姓名全拼”查看上述内容
  52. create view view_product_info_chengweiqiang as select a.code,a.name,b.name1,b.unit_price,b.quantity from product_type a inner join product_chengweiqiang b on a.code=b.type_id;
    
    
  53. 查看订单详情表中的所有产品名称
  54. select a.product_id,b.name1 from order_detail a inner join product_chengweiqiang b on a.product_id = b.id;

  55. 查看产品信息视图中已经有过订单销售记录的产品数据(子查询 in)
  56. 查看订单编号、店铺名称、买家昵称、详细地址、产品名称、采购数量、折后价格
  57. select a.id,b.name,c.nickname,d.detail_address,e.name1,f.purchase_quantity,f.discount_unit_price from order_chengweiqiang a inner join seller_chengweiqiang b on a.seller_id = b.id
        ->      inner join buyer_chengweiqiang c on a.buyer_id = c.id
        ->      inner join address_chengweiqiang d on a.address_id = d.id
        ->      inner join product_chengweiqiang e on b.id = e.seller_id
        ->      inner join order_detail f on a.id=f.order_id
        ->     ;

  58. 创建订单信息视图“view_order_ info_姓名全拼”查看上述内容
  59. create view view_order_info_chengweiqiang as select a.id,b.name,c.nickname,d.detail_address,e.name1,f.purchase_quantity,f.discount_unit_price from order_chengweiqiang a inner join seller_chengweiqiang b on a.seller_id = b.id inner join buyer_chengweiqiang c on a.buyer_id = c.id inner join address_chengweiqiang d on a.address_id = d.id inner join product_chengweiqiang e on b.id = e.seller_id inner join order_detail f on a.id=f.order_id;

任务六、备份数据库

  1. 备份所有数据库,文件名为“all_姓名全拼.sql”(截两张图 命令+文件)
  2. mysqldump -u root -p123456 --all-databases>D:\MYSQL\mysql-8.0.28-winx64\all_chengweiqiang.sql

  3. 备份电子商城数据库,文件名为“mall_姓名全拼.sql”(截两张图 命令+文件)
  4. mysqldump -u root -p123456 mall_chengweiqiang>D:\MYSQL\mysql-8.0.28-winx64\mll_chengweiqiang.sql

  5. 删除电子商城数据库
  6. 创建电子商城数据库“mall_姓名全拼”
  7. 退出MySQL登录
  8. 执行电子商城数据库备份文件
  9. 登录MySQL
  10. 使用电子商城数据库
  11. 查看所有表

 

 

 

 

 

 

 

 

 

 

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
摘要信息: 电子商城系统主要功能包括:用户注册、用户登录、用户查看商城商品、用户购买商品、用户查看购物车并且清空购物车、用户找回账户以及密码、管理员登录、管理员注册、管理员查看用户信息、管理员删除用户信息、管理员删除商品信息、管理员添加商品信息、管理员修改商品信息、退出登录等。 图形可视化界面运行下能够显示系统启动进度条,删除、添加、注册等相关操作时能够弹出窗口加以提示,退出登录或系统时能够做到单击确认退出按钮才退出登录或系统,能够对用户加以提示。 注册用户或是管理员、添加商品信息、购买商品、删除商品或是用户信息、修改商品信息等相关操作时能够判断有无该用户或是商品。 用户在购买商品的时候同时更新商品的库存数量,管理员删除管理员时可以做到同时删除用户的购买信息。 主要内容: 一、项目名称   基于JAVASE的电子商城系统 二、功能要求 1、用户注册 2、用户登录 3、用户查看商品列表 4、用户购买商品 5、用户查看购买商品列表 6、用户清空购物车 7、用户找回账户和密码 8、管理员登录 9、管理员注册 10、查看用户信息 11、查看商品信息 12、删除用户信息 13、删除商品信息 14、添加商品信息 15、修改商品信息 16、退出用户登录 17、退出管理员登录 18、退出商城 三、需求分析 该系统的用户是商城消费者和商城管理者,根据客户的要求,可以注册、登录、购物、查看购物车信息、找回账户和密码,管理员可以对商品信息进行增加、修改、删除操作,可以对用户进行查看和删除。 四、设计思想 1、在控制台与图形可视化界面下运行 2、使用Mysql数据库存取用户登录信息和商品信息 3、使用List存取商品购买信息 4、把程序分为多个类,多个类之间的互相调用。 5、用户或是管理员进行注册、登录时能够提供校验码。 6、用户或是管理员获取数据库信息时能够与数据库进行交互。 7、用户购物要做到简洁明了。 8、用户只需要身份证号码和邮箱地址就能找回账户和密码。 9、注册、删除、修改等操作要有信息提示。 10、用户、管理员进行操作时能够做到操作提示与用户名提示。 11、退出登录或是退出系统时能够做到让用户有所考虑。 五、具体实现   1、技术思路: 界面:基于控制台与图形可视化界面(Swing)实现用户的输入和输出。 程序流程:在函数中利用循环与递归 ,读取用户输入,调用模块实现各个子功能。 2、功能子模块划分: ① 注册模块 ② 登录模块 ③ 查看商品模块(查看商品列表,购买商品) ④ 查看购买商品信息 ⑤ 管理员登录(添加管理员信息,对商品信息进行查看、增加、 修改、删除,对用户信息进行查看、删除,删除用户信息 时能够做到同时删除消费记录) ⑥ 退出系统 六、运行截图 1、商城系统启动进度条(进度条能够做到动态加载): 2、商城主界面: 3、用户注册界面(填写注册信息不符合要求时能够弹窗提示、并 且判断用户名是否重复等): 4、用户登录界面(账户、密码不一致时能弹窗提示): 5、用户服务选择界面(能够提示用户名): 6、购买商品界面(能够判断输入的商品序号是否正确): 7、查看购物车界面(能够一键清空购物车): 8、查看商城商品信息界面: 9、管理员登录界面: 10、找回账户与密码界面: 11、管理员服务选择界面: 12、添加管理员界面: 13、查看用户信息界面: 14、删除用户信息界面: 15、删除商品信息界面: 16、添加商品信息界面: 17、修改商品信息界面: 18、退出账号、管理员登录、商城系统时要有提示:

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值