JPetStore数据库结构

打算好好看看JPetStore,毕竟在新公司也是做网上商城,之前没接触过。为了更好的了解JPetStore,先看看数据库结构。并不是JPetStore的数据库设计得很好从而具有研究价值,只是为了熟悉,所以大家选择性的看吧!

1.商品供应商:每个具体的商品(ITEM)有不同的供应厂商:

create table if not exists supplier (
suppid int not null,--primary key
name varchar(80) null,--name
status varchar(2) not null,
addr1 varchar(80) null,
addr2 varchar(80) null,
city varchar(80) null,
state varchar(80) null,
zip varchar(5) null,
phone varchar(80) null,
primary key (suppid))
type=innodb
min_rows=0
max_rows=1000
pack_keys=default
row_format=default
comment='cadastro de fornecedores';

此表没什么好解释的,基本一看都明白。只是从数据库设计角度来讲有的数据类型和范围还需要斟酌。比如zip可以设为int,phone不必要80个字符等等。

2.登录信息表,只保存用户名(即登录名)和密码,也没什么可解释。其中userid和account表的userid关联:

create table if not exists signon (
username varchar(25) not null,
password varchar(25) not null,
primary key (username))
type=innodb
min_rows=0
max_rows=1000
pack_keys=default
row_format=default
comment='cadastro de usuios';


3.账号表:

create table if not exists account (
userid varchar(80) not null,
email varchar(80) not null,
firstname varchar(80) not null,
lastname varchar(80) not null,
status varchar(2) null,--状态:'OK' or 'AC'
addr1 varchar(80) not null,
addr2 varchar(40) null,
city varchar(80) not null,
state varchar(80) not null,
zip varchar(20) not null,
country varchar(20) not null,
phone varchar(80) not null,
primary key (userid) )
type=innodb
min_rows=0
max_rows=1000
pack_keys=default
row_format=default
comment='cadastro de contas';


4.用于概述信息:包括用户id、语言偏好、喜欢的目录、是否开启List、是否开启Banner。用户账户页面可以显示和配置这些设置,方便个性化设置。

create table if not exists profile (
userid varchar(80) not null,
langpref varchar(80) not null,
favcategory varchar(30),
mylistopt bool,
banneropt bool,
primary key (userid) )
type=innodb
pack_keys=default
row_format=default
comment='cadastro de perfis';


5.banner,原意“旗帜”,存放着喜欢的类别和图片地址:

create table if not exists bannerdata (
favcategory varchar(80) not null,
bannername varchar(255) null,
primary key (favcategory))
type=innodb
pack_keys=default
row_format=default
comment='banner data';


6.订单表:

create table if not exists orders (
orderid int not null,
userid varchar(80) not null,
orderdate date not null,
shipaddr1 varchar(80) not null,
shipaddr2 varchar(80) null,
shipcity varchar(80) not null,
shipstate varchar(80) not null,
shipzip varchar(20) not null,
shipcountry varchar(20) not null,
billaddr1 varchar(80) not null,
billaddr2 varchar(80) null,
billcity varchar(80) not null,
billstate varchar(80) not null,
billzip varchar(20) not null,
billcountry varchar(20) not null,
courier varchar(80) not null,--送货员
totalprice decimal(10,2) not null,
billtofirstname varchar(80) not null,
billtolastname varchar(80) not null,
shiptofirstname varchar(80) not null,
shiptolastname varchar(80) not null,
creditcard varchar(80) not null,
exprdate varchar(7) not null,
cardtype varchar(80) not null,
locale varchar(80) not null,
primary key (orderid) )
type=innodb
pack_keys=default
row_format=default
comment='cadastro de pedidos';


7.订单状态:

create table if not exists orderstatus (
orderid int not null,--主键
linenum int not null,--int型与业务逻辑无关的数据,用于与orderid组成复合主键
timestamp date not null,--时间
status varchar(2) not null,--状态
primary key (orderid, linenum) )
type=innodb
pack_keys=default
row_format=default
comment='status de pedidos';


8.LINEITEM:订单中包含的商品条目,一个订单可以包含多个具体的商品。比如说,一次网上购物生成一条订单(假设订单号为12492),但是这条订单中包含多本书,比如有《Java与模式》2本,《高性能MySQL》一本和《编译原理》3本。

create table if not exists lineitem (
orderid int not null,--订单id
linenum int not null,--无实际意义,用于与orderid组成复合主键
itemid varchar(10) not null,--具体的商品
quantity int not null,--订购该商品的数量
unitprice decimal(10,2) not null,--该具体商品单价*数量所得到的价钱,比如3 --本编译原理的价钱。注意:这不是总的价钱。
primary key (orderid, linenum) )
type=innodb
pack_keys=default
row_format=default
comment='line item';


9.分类:

create table if not exists category (
catid varchar(10) not null,--主键
name varchar(80) null,--类别名称
descn varchar(255) null,--类别描述
primary key (catid) )
type=innodb
pack_keys=default
row_format=default
comment='categorias';


10.商品:

create table if not exists product (
productid varchar(10) not null,
category varchar(10) not null,
name varchar(80) null,
descn varchar(255) null,
primary key (productid) )
type=innodb
pack_keys=default
row_format=default
comment='categorias';


为商品创建类别、商品名的索引

alter table product
add index productcat(category);

alter table product
add index productname(name);

为目录添加索引:
alter table category
add index ixcategoryproduct(catid);

--商品表添加商品类别外键关联,级联删除和更新:
alter table product add foreign key (category)
references category(catid)
on delete restrict
on update restrict;


11.商品详细信息表:存储着商品一些在显示上相对不重要(可以通过延迟加载访问)、变化可能性大(各种attribute)、占用空间大的字段,属于表的纵向切割。

create table if not exists item (
itemid varchar(10) not null,
productid varchar(10) not null,--外键,关联商品id
listprice decimal(10,2) null,--???
unitcost decimal(10,2) null,--单价
supplier int null,--外键,关联供货商
status varchar(2) null,--状态
attr1 varchar(80) null,
attr2 varchar(80) null,
attr3 varchar(80) null,
attr4 varchar(80) null,
attr5 varchar(80) null,
primary key (itemid) )
type=innodb
pack_keys=default
row_format=default
comment='itens';



alter table item
add index itemprod(productid);

alter table item add foreign key (productid)
references product(productid)
on delete restrict
on update restrict;

alter table item add foreign key (supplier)
references supplier(suppid)
on delete restrict
on update restrict;


12.库存表:

create table if not exists inventory (
itemid varchar(10) not null,--商品id
qty int not null,--库存数量
primary key (itemid) )
type=innodb
pack_keys=default
row_format=default
comment='inventory';


13.工具表,用于产生序列:

create table if not exists sequence (
name varchar(30) not null,
nextid int not null,
primary key (name) )
type=innodb
pack_keys=default
row_format=default
comment='inventory';



最后,提供一个链接可以看更加详细的介绍:http://www.docstoc.com/docs/19677923/petstore-%E6%95%B0%E6%8D%AE%E6%A8%A1%E5%9E%8B%E5%88%86%E6%9E%90
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值