Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
a quick question in regards to table design.

 Type(table 1):  typeId  TypeName
                   1     animal
                   2     fish

 Item(table 2):  itemId itemName itemValue typeId
                   1     horse    abc        1
                   2     pig      def        1
                   3     shark    ghi        2  


i want to create only one table
 TypeItem:      itemId  itemName itemValue typeId
                   1     animal   null        0
                   2     fish     null        0
                   3     horse    abc         1
                   4     pig      def         1
                   5     shark    ghi        2 


which way is better?
Posted
Updated 1-Aug-12 2:42am
v3
Comments
Kenneth Haugland 1-Aug-12 8:11am    
Id use two but Im not an expert. There could be upgrades were it is useful.
Unareshraju 1-Aug-12 8:11am    
based on your requirement,
simply think your way......... that's all

Better is such a subjective term. In my opinion, the first way is better. The reason for this is because of the assumption people will have about your data. When they read your table, they will be expecting a type of animal/fish. If they get the generic, that probably won't be what you want. That means you will need to filter these records out of every resultset. These first two rows of data don't mean the same thing as the rest of the data. That is a problem, in my opinion.

I think it makes the issue even easier because you are intending to create a join either way you do this. Therefore, make life easier for yourself and don't mix your types of data in the same table.
 
Share this answer
 
First one is better based on the standard rule of database design. Most of the times, Normalization is suggested for better data handling. Option 1 follows 2-NF.

Read: Database Normalization Basics[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900