Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a product tables some of it fields are fixed and some of optional how to manage thats fields like
Some of product they have expired date and some of product they don't have how to designed table structure

What I have tried:

I just create product table in the product table column is
Productid
Productname
Amount
Quantity
Netamount
Posted
Updated 12-Aug-16 0:18am
Comments
Tomas Takac 8-Aug-16 3:27am    
You can either stuff it all in one table where the optional columns will be nullable or have a table with common attributes and a separate table per product type with specific attributes. If you are familiar with object modelling try to look up "table per hierarchy" and "table per type" - it's about mapping object hierarchies to tables.
awaisshabir 8-Aug-16 10:37am    
i didn't understand what do you mean by common attributes is there any example
please send me the links
Tomas Takac 8-Aug-16 13:58pm    
You said that some products have expired date and some don't. Common attributes would be those that are shared by all the product types like name for example. On the contrary expiry date would only by applicable to some of them.
awaisshabir 8-Aug-16 16:03pm    
you want to say I'm creating one more table called attribute in that table i saved only option fields and its value like

AttributeID, Name, Fixed,product Type
1 ExpDate, Not Fixed,1
Tomas Takac 9-Aug-16 2:52am    
If I have different produdcts:
A (Name, Type)
B (Name, Type, ExpDate)
C (Name, Type, Color)
then I can create the tables like this:
Product (id, name, type)
ProductB (id, expdate)
ProductC (id, color)
Or alternativelly I can have only one table:
Product (id, name, type, expdate nullable, color nullable)
The choice is yours. That is what i tried to tell you in my first comment.

create table showExample
(
Productid int not null,
Productname varchar(50) not null,
Amount money,
Quantity int,
Netamount money
)


Above statement helps you to create a table which have both nullable and non nullable columns. By default a column accepts null value untill and unless "not null"/primary key constraint is applied.
So, in Table showExample, fields Productid and Productname are mandatory while others can have null value.
I hope this solves the confusion.
 
Share this answer
 
Make all fields as Not Null which are fixed and mandatory.
all others are Null that is optional.
 
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