Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a database to store type of food items a shopkeeper holds in the market.
Data tables are as:

1. For Profile table:
a.SID
b.Name
c.Address

2. Fooditemcodes table:
a.itemid (Pkey)
b.itemname

3. Sellingfooditems table:
a.SID (Pkey)
b.itemid1(datatype:bool. default value:null)
c.itemid2, itemid3,....,itemid n

In table Sellingfooditems most of the fields are going to store null values.
Will it be feasible to use the schema as I mentioned above or a better schema would be like one below:

Sellingfooditems table:
a. SID (Pkey)
b. fooditemid (from table fooditemcodes)

There would'nt be any null values in the schema above but fooditemid will repeat for more than one food item being stored by the same shopkeeper.
Posted

Use the second option, the first one is bad design that will give you nothing but problems at every stage.
 
Share this answer
 
Comments
Wendelius 24-Jul-15 9:45am    
Exactly, 5'd
Member 11040029 25-Jul-15 1:46am    
tnx alot!
Well, in my opinion the latter is the only reasonable solution. You don't want to use columns to store data which is row-type. For example consider:
- how referential integrity is enforced
- what happens if you want to buy same item twice
- what if one of the items needs to be taken away
- what if you need more items than you have columns
- how are you going to effectively make queries over that first structure and so on...
 
Share this answer
 
Comments
Member 11040029 25-Jul-15 1:46am    
Tnx alot!
Wendelius 25-Jul-15 1:49am    
You're most welcome :)

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