建表:mysql 电子商城建表参考



[sql]  view plain  copy
  1. -- 创建数据库  
  2. drop database if exists haoyigou;  
  3. create database haoyigou charset utf8;  
  4. use haoyigou;  
  5.   
  6. -- 管理员表  
  7. drop table if exists hyg_admin;  
  8. create table  hyg_admin(  
  9. id tinyint unsigned auto_increment key comment 'id',  
  10. username varchar(20) not null unique comment '用户名',  
  11. password char(32) not null comment '用户密码:md5加密',  
  12. email varchar(50) not null comment '邮箱地址'  
  13. );  
  14. -- 新增管理员  
  15. insert into hyg_admin values(null,'admin',md5('admin'),'[email protected]');  
  16.   
  17. -- 用户表  
  18. drop table if exists hyg_user;  
  19. create table  hyg_user(  
  20. hyg_id int primary key auto_increment comment '主键',  
  21. hyg_username varchar(20) not null unique comment '用户名必须唯一',  
  22. hyg_password char(32) not null comment '用户密码:md5加密',  
  23. hyg_email varchar(50) not null comment '邮箱地址'  
  24. )charset utf8;  
  25. -- 新增用户信息  
  26. insert into hyg_user values(null,'admin',md5('admin'),'[email protected]');  
  27.   
  28. -- 用户收货信息表  
  29. drop table if exists hyg_delivery;  
  30. create table  hyg_delivery(  
  31. user_id int  comment '用户id',  
  32. hyg_name varchar(10) comment '收货人姓名',  
  33. hyg_phone varchar(11)  comment '手机',  
  34. hyg_postcode char(10)  comment '邮政编码',  
  35. hyg_addr varchar(30) comment '详细地址',  
  36. hyg_time varchar(30) comment '送货时间'  
  37. )charset utf8;  
  38.   
  39. --测试数据  
  40. INSERT INTO `haoyigou`.`hyg_delivery` (`user_id`, `hyg_name`, `hyg_phone`, `hyg_postcode`, `hyg_addr`, `hyg_time`) VALUES ('1''黄晓明''15878521654''525300''广东省广州市天河街道11''不限');  
  41. --商品表  
  42. drop table if exists hyg_goods;  
  43. create table hyg_goods(  
  44. goods_id int primary key auto_increment comment '主键',  
  45. goods_name varchar(120) comment '商品名称',  
  46. cat_id smallint(5) comment '栏目id',  
  47. brand_id int comment '品牌id',  
  48. goods_score int comment '可使用积分',  
  49. goods_sn varchar(60) comment '货号',  
  50. goods_number int comment '库存量',  
  51. shop_mprice decimal(10,2) comment '市场价格',  
  52. shop_price decimal(10,2) comment '本店价格',  
  53. goods_desc text comment '商品详细描述',  
  54. add_time int comment '上架时间',  
  55. ud_time int comment '更新时间',  
  56. is_delete tinyint(1) comment '是否已删除',  
  57. goods_image varchar(255) comment '图片名称',  
  58. goods_thumb varchar(255) comment '缩略图名称',  
  59. goods_sthumb varchar(255) comment '小缩略图片名称',  
  60. is_best tinyint(1) comment '是否精品',  
  61. is_new  tinyint(1) comment '是否新品',  
  62. is_hot  tinyint(1) comment '是否热销',  
  63. is_promote tinyint(1) comment '低价促销'  
  64. )charset utf8;  
  65. --插入商品数据  
  66. INSERT INTO `haoyigou`.`hyg_goods` (`goods_id`, `goods_name`, `cat_id`, `brand_id`, `goods_score`, `goods_sn`, `goods_number`, `shop_mprice`, `shop_price`, `goods_desc`, `add_time`, `ud_time`, `is_delete`, `goods_image`, `goods_thumb`, `goods_sthumb`, `is_best`, `is_new`, `is_hot`, `is_promote`) VALUES (NULL'iphone8''1''2''1200''hyg_20152612''11''9000''8000''一步好手机''12345678''58495621''0''17_P_1241969394354.jpg''17_thumb_P_1241969394537.jpg''small_thumb_P_1241969394537.jpg''1''1''1''1');  
  67. INSERT INTO `haoyigou`.`hyg_goods` (`goods_id`, `goods_name`, `cat_id`, `brand_id`, `goods_score`, `goods_sn`, `goods_number`, `shop_mprice`, `shop_price`, `goods_desc`, `add_time`, `ud_time`, `is_delete`, `goods_image`, `goods_thumb`, `goods_sthumb`, `is_best`, `is_new`, `is_hot`, `is_promote`) VALUES (NULL'iphone8''1''2''1200''hyg_20152612''11''9000''8000''强大手机的日常''12345678''58495621''0''17_P_1241969394354.jpg''17_thumb_P_1241969394537.jpg''small_thumb_P_1241969394537.jpg''0''0''0''0');  
  68.   
  69. -- 分类表  
  70. drop table if exists hyg_category;  
  71. create table hyg_category(  
  72. cat_id int primary key auto_increment comment '主键',  
  73. cat_name varchar(30) comment '栏目名称',  
  74. parent_id int comment '栏目的父id'  
  75.   
  76. )charset utf8;  
  77.   
  78. -- 品牌表  
  79. drop table if exists hyg_brand;  
  80. create table hyg_brand(  
  81. brd_id int primary key auto_increment comment '主键',  
  82. cat_name varchar(30) comment '品牌名称'  
  83. )charset utf8;  
  84. --添加品牌示例  
  85. insert into hyg_brand values(null,'诺基亚'),(null,'三星'),(null,'苹果');  
  86.   
  87. -- 商品图片表  
  88. drop table if exists shop_album;  
  89. create table shop_album(  
  90. id int unsigned auto_increment key comment 'id',  
  91. pid int unsigned not null comment '商品id',  
  92. albumPath varchar(50) not null comment '图片路径',  
  93. goods_sthumb varchar(255) comment '小缩略图片名称'  
  94. );  
  95.   
  96.   
  97. --用户留言表  
  98. drop table if exists hyg_message;  
  99. create table hyg_message(  
  100. message_id int primary key auto_increment comment '自增',  
  101. user_id int comment '留言用户的id',  
  102. goods_id int default '0' comment '所在商品id,0代表网站留言',  
  103. message_type int comment '留言类型: 留言 投诉 询问 售后 求购',  
  104. message_content text comment '留言内容',  
  105. message_date int comment '留言时间'  
  106. )charset utf8;  
  107. --/*---------------------------------*/  
  108. --//--- 订单表已改!!  
  109. --/*---------------------------------*/  
  110.   
  111. --原订单表  
  112. --drop table if exists hyg_order;  
  113. --create table hyg_order(  
  114. --id int primary key auto_increment comment '自增',  
  115. --order_id int comment '订单号',  
  116. --order_time int comment '下单时间',  
  117. --order_money decimal(10,2) comment '订单金额',  
  118. --order_stat tinyint comment  '订单状态',  
  119. --order_exp tinyint comment  '送货方式',  
  120. --order_pay tinyint comment  '支付方式',  
  121. --goods_id int,  
  122. --order_mes varchar(50) comment '订单留言'  
  123. --)charset utf8;  
  124.   
  125.   
  126. --新订单表  
  127. drop table if exists hyg_order;  
  128. create table hyg_order(  
  129. id int primary key auto_increment comment '自增',  
  130. order_id varchar(30) comment '订单号',  
  131. user_id int comment '用户id',  
  132. order_good text comment '拼凑商品id和数量:1|3-2|1',  
  133. order_time int comment '下单时间(时间戳)',  
  134. order_money decimal(10,2) comment '订单金额',  
  135. hyg_name varchar(10) comment '收货人姓名',  
  136. hyg_phone varchar(11)  comment '手机',  
  137. hyg_postcode char(10)  default '' comment '邮政编码',  
  138. hyg_addr varchar(30) comment '详细地址',  
  139. order_stat tinyint default '1' comment  '订单状态',  
  140. order_exp tinyint default '1' comment  '送货方式',  
  141. order_pay tinyint default '1' comment  '支付方式',  
  142. order_mes varchar(50) default '' comment '订单留言'  
  143. )charset utf8;  
  144.   
  145.   
  146. --订单详情表(现实情况会用到)  
  147. --drop table if exists hyg_orderdetail;  
  148. --create table hyg_orderdetail(  
  149. --order_id varchar(15) comment '订单号',  
  150. --goods_id int comment '商品的id',  
  151. --sale_num int comment '购买数量'  
  152. --)charset utf8;  
  153.   
  154. --增加订单测试数据  
  155. insert into hyg_order values(null,'hyg_00000001','1','1|3-2|1','20150126','500','小王','15845261547','512515','中国广东广州天朗明居',default,default,default,'尽快发货!');  
  156. insert into hyg_order values(null,'hyg_00000002','2','2|1-2|2','20150127','500','小王','15845261547','512515','中国广东广州塘东',default,default,default,'期待!');  
  157.   
  158. --/*---------------------------------*/  
  159. --//--- 购物车表已改!!  
  160. --/*---------------------------------*/  
  161. --原购物车  
  162. --drop table if exists hyg_cart;  
  163. --create table hyg_cart(  
  164. --cart_id int primary key auto_increment comment '自增',  
  165. --goods_id int comment '商品的id',  
  166. --select_color varchar(20) comment '选中商品的颜色',  
  167. --sale_num tinyint comment '购买数量',  
  168. --shop_price tinyint comment '本店购买价格'  
  169. --)charset utf8;  
  170.   
  171. --新购物车  
  172. drop table if exists hyg_cart;  
  173. create table hyg_cart(  
  174. cart_id int primary key auto_increment comment '自增',  
  175. u_id int not null comment '买家id',  
  176. goods_id int comment '商品的id',  
  177. price_count int comment '金额小计',  
  178. mprice_count int comment '市场价格小计',  
  179. sale_num int comment '购买数量'  
  180. )charset utf8;  
  181. --增加测试数据  
  182. INSERT INTO `haoyigou`.`hyg_cart` VALUES (NULL'1''1''16000','18000','2');  
  183. INSERT INTO `haoyigou`.`hyg_cart` VALUES (NULL , '2''2''16000','18000','1');  
  184.   
  185. -- 收藏表  
  186. create table hyg_college(  
  187. id int primary key auto_increment comment '主键',  
  188. user_id int  comment '用户id',  
  189. goods_id int comment '商品id'  
  190.   
  191. )charset utf8;  
  192.   
  193.   
  194.   
  195. alter table hyg_category add cat_sort tinyint default 20 comment '手机分类排序';  
[sql]  view plain  copy
  1. -- 创建数据库  
  2. drop database if exists haoyigou;  
  3. create database haoyigou charset utf8;  
  4. use haoyigou;  
  5.   
  6. -- 管理员表  
  7. drop table if exists hyg_admin;  
  8. create table  hyg_admin(  
  9. id tinyint unsigned auto_increment key comment 'id',  
  10. username varchar(20) not null unique comment '用户名',  
  11. password char(32) not null comment '用户密码:md5加密',  
  12. email varchar(50) not null comment '邮箱地址'  
  13. );  
  14. -- 新增管理员  
  15. insert into hyg_admin values(null,'admin',md5('admin'),'[email protected]');  
  16.   
  17. -- 用户表  
  18. drop table if exists hyg_user;  
  19. create table  hyg_user(  
  20. hyg_id int primary key auto_increment comment '主键',  
  21. hyg_username varchar(20) not null unique comment '用户名必须唯一',  
  22. hyg_password char(32) not null comment '用户密码:md5加密',  
  23. hyg_email varchar(50) not null comment '邮箱地址'  
  24. )charset utf8;  
  25. -- 新增用户信息  
  26. insert into hyg_user values(null,'admin',md5('admin'),'[email protected]');  
  27.   
  28. -- 用户收货信息表  
  29. drop table if exists hyg_delivery;  
  30. create table  hyg_delivery(  
  31. user_id int  comment '用户id',  
  32. hyg_name varchar(10) comment '收货人姓名',  
  33. hyg_phone varchar(11)  comment '手机',  
  34. hyg_postcode char(10)  comment '邮政编码',  
  35. hyg_addr varchar(30) comment '详细地址',  
  36. hyg_time varchar(30) comment '送货时间'  
  37. )charset utf8;  
  38.   
  39. --测试数据  
  40. INSERT INTO `haoyigou`.`hyg_delivery` (`user_id`, `hyg_name`, `hyg_phone`, `hyg_postcode`, `hyg_addr`, `hyg_time`) VALUES ('1''黄晓明''15878521654''525300''广东省广州市天河街道11''不限');  
  41. --商品表  
  42. drop table if exists hyg_goods;  
  43. create table hyg_goods(  
  44. goods_id int primary key auto_increment comment '主键',  
  45. goods_name varchar(120) comment '商品名称',  
  46. cat_id smallint(5) comment '栏目id',  
  47. brand_id int comment '品牌id',  
  48. goods_score int comment '可使用积分',  
  49. goods_sn varchar(60) comment '货号',  
  50. goods_number int comment '库存量',  
  51. shop_mprice decimal(10,2) comment '市场价格',  
  52. shop_price decimal(10,2) comment '本店价格',  
  53. goods_desc text comment '商品详细描述',  
  54. add_time int comment '上架时间',  
  55. ud_time int comment '更新时间',  
  56. is_delete tinyint(1) comment '是否已删除',  
  57. goods_image varchar(255) comment '图片名称',  
  58. goods_thumb varchar(255) comment '缩略图名称',  
  59. goods_sthumb varchar(255) comment '小缩略图片名称',  
  60. is_best tinyint(1) comment '是否精品',  
  61. is_new  tinyint(1) comment '是否新品',  
  62. is_hot  tinyint(1) comment '是否热销',  
  63. is_promote tinyint(1) comment '低价促销'  
  64. )charset utf8;  
  65. --插入商品数据  
  66. INSERT INTO `haoyigou`.`hyg_goods` (`goods_id`, `goods_name`, `cat_id`, `brand_id`, `goods_score`, `goods_sn`, `goods_number`, `shop_mprice`, `shop_price`, `goods_desc`, `add_time`, `ud_time`, `is_delete`, `goods_image`, `goods_thumb`, `goods_sthumb`, `is_best`, `is_new`, `is_hot`, `is_promote`) VALUES (NULL'iphone8''1''2''1200''hyg_20152612''11''9000''8000''一步好手机''12345678''58495621''0''17_P_1241969394354.jpg''17_thumb_P_1241969394537.jpg''small_thumb_P_1241969394537.jpg''1''1''1''1');  
  67. INSERT INTO `haoyigou`.`hyg_goods` (`goods_id`, `goods_name`, `cat_id`, `brand_id`, `goods_score`, `goods_sn`, `goods_number`, `shop_mprice`, `shop_price`, `goods_desc`, `add_time`, `ud_time`, `is_delete`, `goods_image`, `goods_thumb`, `goods_sthumb`, `is_best`, `is_new`, `is_hot`, `is_promote`) VALUES (NULL'iphone8''1''2''1200''hyg_20152612''11''9000''8000''强大手机的日常''12345678''58495621''0''17_P_1241969394354.jpg''17_thumb_P_1241969394537.jpg''small_thumb_P_1241969394537.jpg''0''0''0''0');  
  68.   
  69. -- 分类表  
  70. drop table if exists hyg_category;  
  71. create table hyg_category(  
  72. cat_id int primary key auto_increment comment '主键',  
  73. cat_name varchar(30) comment '栏目名称',  
  74. parent_id int comment '栏目的父id'  
  75.   
  76. )charset utf8;  
  77.   
  78. -- 品牌表  
  79. drop table if exists hyg_brand;  
  80. create table hyg_brand(  
  81. brd_id int primary key auto_increment comment '主键',  
  82. cat_name varchar(30) comment '品牌名称'  
  83. )charset utf8;  
  84. --添加品牌示例  
  85. insert into hyg_brand values(null,'诺基亚'),(null,'三星'),(null,'苹果');  
  86.   
  87. -- 商品图片表  
  88. drop table if exists shop_album;  
  89. create table shop_album(  
  90. id int unsigned auto_increment key comment 'id',  
  91. pid int unsigned not null comment '商品id',  
  92. albumPath varchar(50) not null comment '图片路径',  
  93. goods_sthumb varchar(255) comment '小缩略图片名称'  
  94. );  
  95.   
  96.   
  97. --用户留言表  
  98. drop table if exists hyg_message;  
  99. create table hyg_message(  
  100. message_id int primary key auto_increment comment '自增',  
  101. user_id int comment '留言用户的id',  
  102. goods_id int default '0' comment '所在商品id,0代表网站留言',  
  103. message_type int comment '留言类型: 留言 投诉 询问 售后 求购',  
  104. message_content text comment '留言内容',  
  105. message_date int comment '留言时间'  
  106. )charset utf8;  
  107. --/*---------------------------------*/  
  108. --//--- 订单表已改!!  
  109. --/*---------------------------------*/  
  110.   
  111. --原订单表  
  112. --drop table if exists hyg_order;  
  113. --create table hyg_order(  
  114. --id int primary key auto_increment comment '自增',  
  115. --order_id int comment '订单号',  
  116. --order_time int comment '下单时间',  
  117. --order_money decimal(10,2) comment '订单金额',  
  118. --order_stat tinyint comment  '订单状态',  
  119. --order_exp tinyint comment  '送货方式',  
  120. --order_pay tinyint comment  '支付方式',  
  121. --goods_id int,  
  122. --order_mes varchar(50) comment '订单留言'  
  123. --)charset utf8;  
  124.   
  125.   
  126. --新订单表  
  127. drop table if exists hyg_order;  
  128. create table hyg_order(  
  129. id int primary key auto_increment comment '自增',  
  130. order_id varchar(30) comment '订单号',  
  131. user_id int comment '用户id',  
  132. order_good text comment '拼凑商品id和数量:1|3-2|1',  
  133. order_time int comment '下单时间(时间戳)',  
  134. order_money decimal(10,2) comment '订单金额',  
  135. hyg_name varchar(10) comment '收货人姓名',  
  136. hyg_phone varchar(11)  comment '手机',  
  137. hyg_postcode char(10)  default '' comment '邮政编码',  
  138. hyg_addr varchar(30) comment '详细地址',  
  139. order_stat tinyint default '1' comment  '订单状态',  
  140. order_exp tinyint default '1' comment  '送货方式',  
  141. order_pay tinyint default '1' comment  '支付方式',  
  142. order_mes varchar(50) default '' comment '订单留言'  
  143. )charset utf8;  
  144.   
  145.   
  146. --订单详情表(现实情况会用到)  
  147. --drop table if exists hyg_orderdetail;  
  148. --create table hyg_orderdetail(  
  149. --order_id varchar(15) comment '订单号',  
  150. --goods_id int comment '商品的id',  
  151. --sale_num int comment '购买数量'  
  152. --)charset utf8;  
  153.   
  154. --增加订单测试数据  
  155. insert into hyg_order values(null,'hyg_00000001','1','1|3-2|1','20150126','500','小王','15845261547','512515','中国广东广州天朗明居',default,default,default,'尽快发货!');  
  156. insert into hyg_order values(null,'hyg_00000002','2','2|1-2|2','20150127','500','小王','15845261547','512515','中国广东广州塘东',default,default,default,'期待!');  
  157.   
  158. --/*---------------------------------*/  
  159. --//--- 购物车表已改!!  
  160. --/*---------------------------------*/  
  161. --原购物车  
  162. --drop table if exists hyg_cart;  
  163. --create table hyg_cart(  
  164. --cart_id int primary key auto_increment comment '自增',  
  165. --goods_id int comment '商品的id',  
  166. --select_color varchar(20) comment '选中商品的颜色',  
  167. --sale_num tinyint comment '购买数量',  
  168. --shop_price tinyint comment '本店购买价格'  
  169. --)charset utf8;  
  170.   
  171. --新购物车  
  172. drop table if exists hyg_cart;  
  173. create table hyg_cart(  
  174. cart_id int primary key auto_increment comment '自增',  
  175. u_id int not null comment '买家id',  
  176. goods_id int comment '商品的id',  
  177. price_count int comment '金额小计',  
  178. mprice_count int comment '市场价格小计',  
  179. sale_num int comment '购买数量'  
  180. )charset utf8;  
  181. --增加测试数据  
  182. INSERT INTO `haoyigou`.`hyg_cart` VALUES (NULL'1''1''16000','18000','2');  
  183. INSERT INTO `haoyigou`.`hyg_cart` VALUES (NULL , '2''2''16000','18000','1');  
  184.   
  185. -- 收藏表  
  186. create table hyg_college(  
  187. id int primary key auto_increment comment '主键',  
  188. user_id int  comment '用户id',  
  189. goods_id int comment '商品id'  
  190.   
  191. )charset utf8;  
  192.   
  193.   
  194.   
  195. alter table hyg_category add cat_sort tinyint default 20 comment '手机分类排序';  

猜你喜欢

转载自blog.csdn.net/qq_34306360/article/details/79721660
今日推荐