02(maven+SSH)網上商城項目實戰之數據庫設計(PMD)

數據庫物理模型:

wKioL1ZBl6uhW9tMAADEn64jyds964.png

數據庫SQL:

drop table if exists T_CartItems;
drop table if exists T_Consignee;
drop table if exists T_Goods;
drop table if exists T_Order;
drop table if exists T_OrderItems;
drop table if exists T_User;
drop table if exists T_comment;
create table T_CartItems
(
   cartItems_id         int not null auto_increment,
   goods_id             int,
   user_id              int,
   cartItems_count      int not null,
   primary key (cartItems_id)
);
create table T_Consignee
(
   consignee_id         int not null,
   user_id              int,
   consignee_name       varchar(20) not null,
   consignee_phone      varchar(11) not null,
   consignee_postcode   varchar(6),
   consignee_address    varchar(1000) not null,
   primary key (consignee_id)
);
create table T_Goods
(
   goods_id             int not null auto_increment,
   goods_name           varchar(20) not null,
   goods_price          double not null,
   goods_url            varchar(10),
   goods_memo           varchar(1000),
   goods_state          varchar(10) comment '1.上架   2.下架',
   primary key (goods_id)
);
create table T_Order
(
   order_id             int not null,
   user_id              int,
   consignee_id         int,
   order_createTime     datetime not null,
   order_bill           double not null,
   order_state          varchar(10) not null comment '1.待付款  2.已付款',
   primary key (order_id)
);
create table T_OrderItems
(
   orderItems_id        int not null auto_increment,
   goods_id             int,
   order_id             int,
   orderItems_name      varchar(100) not null,
   orderItems_price     double not null,
   orderItems_count     int not null,
   primary key (orderItems_id)
);
create table T_User
(
   user_id              int not null auto_increment,
   user_pass            varchar(100) not null,
   user_nick            varchar(20) not null,
   user_name            varchar(20) not null,
   user_phone           varchar(11) not null,
   user_sex             varchar(10) not null,
   user_type            varchar(10) comment '1.普通用戶 2.管理員',
   primary key (user_id)
);
create table T_comment
(
   comment_id           int not null auto_increment,
   user_id              int,
   goods_id             int,
   comment_memo         varchar(1000),
   comment_data         datetime,
   primary key (comment_id)
);
alter table T_CartItems add constraint fk_cartItems_goods foreign key (goods_id)
      references T_Goods (goods_id) on delete restrict on update restrict;
      
alter table T_CartItems add constraint fk_cartItems_user foreign key (user_id)
      references T_User (user_id) on delete restrict on update restrict;
      
alter table T_Consignee add constraint fk_consignee_user foreign key (user_id)
      references T_User (user_id) on delete restrict on update restrict;
      
alter table T_Order add constraint fk_order_consignee foreign key (consignee_id)
      references T_Consignee (consignee_id) on delete restrict on update restrict;
      
alter table T_Order add constraint fk_order_user foreign key (user_id)
      references T_User (user_id) on delete restrict on update restrict;
      
alter table T_OrderItems add constraint fk_orderItems_goods foreign key (goods_id)
      references T_Goods (goods_id) on delete restrict on update restrict;
      
alter table T_OrderItems add constraint fk_orderItems_order foreign key (order_id)
      references T_Order (order_id) on delete restrict on update restrict;
      
alter table T_comment add constraint fk_comment_goods foreign key (goods_id)
      references T_Goods (goods_id) on delete restrict on update restrict;
      
alter table T_comment add constraint fk_comment_user foreign key (user_id)
      references T_User (user_id) on delete restrict on update restrict;


本文出自 “老牛Java” 博客,請務必保留此出處http://liuyj.blog.51cto.com/2340749/1711450

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章