现在做一个商场的网站,网站中有各种商品,比如手机,化妆品,服装···,每种商品的属性是不同的,手机有手机的参数,服装又有服装的参数,而且与手机的参数完全不同,但是又同属于商品,如果只做一个商品表,那这么多的属性如何处理啊。本人数据库这比较菜鸟,希望大虾指点迷津。

解决方案 »

  1.   

    手机表:
    ID 商品ID 品牌 型号 颜色 是否翻盖 等……
    化妆品表:
    ID 商品ID 品牌 颜色 等……
    服装表:
    ID 商品ID 品牌 男女款式 等……总表:
    ID 商品ID 种类 等……我随便写的,其中化妆品表可能还要根据是那种化妆品来具体细分?
      

  2.   


    个人愚见tab1:总商品
    ID--TYPE--......tab2:商品
    PID--PTYPE--ARG1--ARG2--....ARGn
      

  3.   

    yy一个,请各位高人指点
    use tempdb;--属性表
    create table attribute
    (
    attributeid int identity(1,1) not null primary key,
    categoryid int not null,
    attributename nvarchar(10) not null
    );
    insert into attribute(categoryid,attributename)
    values
    (1,'操作系统'),
    (2,'颜色');--分类表
    create table category
    (
    categoryid int identity(1,1) not null primary key,
    categoryname nvarchar(10) not null
    );
    insert into category(categoryid,categoryname)
    values
    (1,'手机'),
    (2,'服装');--商品表
    create table goods
    (
    goodsid int identity(1,1) not null primary key,
    categoryid int not null,
    goodsname nvarchar(10) not null
    );
    insert into goods(categoryid,goodsname)
    values
    (1,'华为C8500'),
    (1,'iPhone 4'),
    (1,'HTC S1'),
    (2,'阿迪王春哥限量版板鞋');--商品属性表
    create table goods_attribute
    (
    goods_attribute_id int identity(1,1) not null primary key,
    goodsid int not null,
    attributeid int not null,
    attributevalue int not null --属性值
    );
    insert into goods_attribute(goodsid,attributeid,attributevalue)
    values
    (1,1,'Android系统'), --描述 华为C8500 的操作系统为Android
    (1,2,'银灰色'), --描述 华为C8500 的颜色为银灰色
    (2,1,'iPhone系统'), --描述 iPhone 4 的操作系统为iPhone
    (2,2,'黑色'), --描述 iPhone 4 的颜色为银灰色
    (3,1,'Windows Mobile 6系统'),
    (3,2,'黑色'),
    (4,2,'粉色'), --描述 阿迪王春哥限量版板鞋 的颜色为粉色