0

Different product has different set of different specifications. The products are also categorised. How to deisngn this kind of need? Any idea will be highly appreciated. For example -

Sony Xperia ZL

    General Features
        Form - Touch
        SIM  - Single SIM, GSM 
    Software
        OS Version   - Android OS, v4.1.2 (Jelly Bean)
        Operating Freq   - GSM - 850, 900, 1800, 1900; UMTS - 2100 
    Display
        Type -  TFT Capacitive
        Size -  5-inch 



LG HD LED Television

    GENERAL
        Model   47LN5710
        Screen Type     -
        Display Size    47 Inch 

    VIDEO FEATURES
        Aspect Ratio    -
        Dynamic Ratio   -
        View Angle  178 Degree 
Samik Chattopadhyay
  • 1,820
  • 6
  • 23
  • 34
  • See my [similar post](http://stackoverflow.com/questions/21010251/inventory-management-with-stock-options/21113170#21113170) , may come in handy. – Mohsen Heydari Jan 15 '14 at 08:05

1 Answers1

4

It depends on what you're using it for. There's an easy solution of creating a table such as 'Spec Attributes' with just two three columns: Product Id, Spec Name, Spec Value. This would be an easy fix - but offers no support or data integrity.

A better solution would be to put some safeguards around attributes. Similar to the above, it would involve having a table which would store your 'columns' (i.e. SIM, OS Version) as rows. I would suggest having pre-defined attributes and even 'types' to confine the attributes you're using to make it easier for querying.

For Example,

  DeviceTypes
  DeviceTypeId |     Name
  01           |     Camera
  02           |     Television
  03           |     Mobile Phone

  Category
  CategoryId   |     Name
  01           |     General
  02           |     Video Features

  DeviceAttributeTypes
  DeviceAttribTypeId| DeviceTypeId | CategoryId    |AttributeName  |    DataType
  01                | 01           | 01            | SIM           | Varchar
  02                | 01           | 01            | Size          | NUMBER
  03                | 02           | 02            | Display Size  | NUMBER
  04                | 02           | 01            | Model         | Varchar

  DeviceAttribut
  DeviceId  |  DeviceAttirbTypeId |  Value  
  13        |  01                 |  Single Sim, GSM
  13        |  02                 |  5
  14        |  04                 |  47LN5710

In this example, you would 'hard-code' the Device Types and Category tables with the attributes and types you would like. This gives you option of filtering your attributes by the Type or Category of them.

i.e. To get a list of all devices and their attributes you would could use the below query below. Then you could add in 'WHERE' on the ID's or names of categories or device types

  SELECT d.DeviceName
  ,      dat.AttributeName
  ,      dar.Value
  FROM   Device d
         LEFT JOIN DeviceAttribute da
           ON d.DeviceId = da.DeviceId
         LEFT JOIN DeviceAttributeType dat
           ON da.DeviceAttribTypeId = dat.DeviceAttribtypeId

To make queries where you need to return a resultset with the attributes as columns, I always use the ;with annotation. (Example here)

Community
  • 1
  • 1
Scott Allen
  • 513
  • 2
  • 13