I have an existing table which requires different columns for different record. do I need to split it into multiple tables to reduce the redundancy?
Table1:
productId typeId commonAttr1 commonAttr2 attrA1 attrB1 attrB2
_________________________________________________________________
1 1 1Avalue1 1Avalue2 value1
2 1 1Avalue1 1Avalue2 value2
3 2 2Bvalue1 2Bvalue2 value3 value4
4 2 2Bvalue3 2Bvalue4 value5 value6
The "attrA1" is only for recored with typeId=1, "attrB1" and "attrB2" are only for records with typeId=2, "commonAttr1", "commonAttr2" are for both.
There might be 3 options:
1. Do not change. accept the data redundancy.
2. Move "attrA1" to new table2, move "attrB1","attrB2" to new table3.It'll be like:
Table1:
productId typeId commonAttr1 commonAttr2
___________________________________________
1 1 1Avalue1 1Avalue2
2 1 1Avalue1 1Avalue2
3 2 2Bvalue1 2Bvalue2
4 2 2Bvalue3 2Bvalue4
Table2:
productId attrA1
__________________
1 value1
2 value2
Table3:
productId attrB1 attrB2
___________________________
3 value3 value4
4 value5 value6
3.Create a new table to store the column as Key/Value
Table1:
productId typeId commonAttr1 commonAttr2
___________________________________________
1 1 1Avalue1 1Avalue2
2 1 1Avalue1 1Avalue2
3 2 2Bvalue1 2Bvalue2
4 2 2Bvalue3 2Bvalue4
Table2:
productId typeId key value
____________________________________
1 1 attrA1 value1
2 1 attrA1 value2
3 2 attrB1 value3
3 2 attrB2 value4
4 2 attrB1 value5
4 2 attrB2 value6
Which option is better or is there any other solution? Personally I suppose option 2 is better.