Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am making a app in which one table is for storing client information and other is the for products I have. There is no limit of products as any new product will be added on it.

Each time I add a client I give options to select any product from all list of products by selecting checkbox of each product.After all this process user will click submit button. I want to store the Id of each product selected and store it into database with customer Id.But I am very confused in database design.Please Help...

[edit]Spurious code block removed - OriginalGriff[/edit]
Posted
Updated 26-Nov-12 0:01am
v3

Sounds like you need to have three tables, not two.
Customer table:
CID, Name, Address, etc.

Product table:
PID, Name, Description, Price, Image, etc.

CustomerOrderDetail:
OID, CID, PID, Date, etc.

It may be that you want a fourth table to handle individual orders from a customer: Ones that get delivered together, invoiced toghether, paid together, and so forth.
In which case you would replace the third table with two.
CustomerOrder:
COID, CID, Date, status, etc.

CustomerOrderDetail:
CODID, COID, PID, etc.

The later setup is more normal when you might have a customer making an order each week, say.
 
Share this answer
 
Comments
jaswinder Singh03 26-Nov-12 5:01am    
I am satisfy with your answer Sir , but I want to confirm that if customer will order 10 products then is there 10 records will submitted to CustomerOrderDetail Table with same cust_id and different pr_id's......Thanks for answering my question
OriginalGriff 26-Nov-12 5:18am    
Yes - that is the idea exactly.
Or, if you keep it as they do for invoices, then one CustomerOrder row per invoice (with a suctomer id), and a number of CustomerOrderDetial rows with one COID and a product ID each.
jaswinder Singh03 26-Nov-12 5:20am    
Thanks Sir
shaikh-adil 12-Dec-12 0:06am    
+5
Hi,
You can maintain 2 tables in your database namely, TblProduct and TblClient.

for ex:
SQL
create table TblProduct(
ProductID int primary key not null,
ProductName varchar(50) not null,
ProductDetails varchar(100) not null)

and
SQL
create table TblClient(
ClientId int primary key not null,
ClientName varchar(50) not null,
ClientDetails varchar(100) not null,
ProductID1 int not null)


Later you can use a query to retrieve what all details you need and display it as your end result.
SQL
select * from TblProduct
will yield:
SQL
ProductID ProductName ProductDetails 
1	BMW	vehicles
2	Lenovo 	PC
3	HP	PC
4	Kingston Peripherals

SQL
select * from TblClient
will yield:
SQL
ClientId ClientName ClientDetails ProductID1 
100	YY	BeachSide	1
101	XX	RiverSide	2
102	ZZ	CountrySide	5
103	AA	No Details	4
105	BB	TownHall	6


Then you might use a query like:
select TblClient.* from TblClient  join TblProduct on TblProduct.ProductID=TblClient.ProductID1

The answer based upon the above entries will yield:
SQL
ClientId ClientName ClientDetails ProductID1  
100	YY	BeachSide	1
101	XX	RiverSide	2
103	AA	No Details	4


It gives the details of the clients who have purchased the product which is present in the product list.You can store it in a separate table if you want.
Hope it helps
 
Share this answer
 
Comments
jaswinder Singh03 26-Nov-12 5:16am    
Hi Anurag , Your solution is only for one to one relation means if customer buys more than one product it will not prove useful.
Anurag Sinha V 26-Nov-12 5:22am    
Yeah thx for pointing..In that case you can have a 3rd table having fewer more details such as orderid,clientid,productid etc...and then you cn retrieve using joins wat all you need.. :)
shaikh-adil 12-Dec-12 0:06am    
+5

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