Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi All
I have a table with the following entries:-
CustName |	CustId |CustomerType|ProdID |ProdName|Units|PurchaseDate
Mr.James Butt	100JSBTM	R	1001	SVS1	5	6/15/2016

Mrs.JosephineDarakjy 101JEDYF	F	1011	SVS1	11	6/15/2016

Mr.ArtVenere	102ATVEM	F	1021	SVV2	4	6/15/2016


Now ProductName has further subtypes with the common group_ProdID and (minor extension to sub product ids).The thing is if a person purchases few subtypes of a specific product,all the customer related entries seems needs to rentered. Any workaround this problem to avoid the repetitive entries)

What I have tried:

 CustName  |	CustId |CustomerType| ProdID    | ProdName|Units |PurchaseDate
Mr.James Butt	    100JSBTM	R	     1001SVST1	 SVS1T1	   5	  6/15/2016
Mr.James Butt	    100JSBTM	R	     1001SVST2	 SVS1T2	   5	  6/15/2016
Mr.James Butt	    100JSBTM	R	     1001SVST3	 SVS1T3	   5	  6/15/2016
Posted
Updated 15-Jun-16 2:11am
v2

1 solution

You need to learn about Database Normalisation
The Basics of Database Normalization[^]
1NF, 2NF, 3NF and BCNF in Database Normalization | DBMS Tutorial | Studytonight[^]
Database Normalization Techniques[^]

In this case you could (for example) have tables for Customer, Product and Orders.
SQL
create table Customer
(
	Id int identity(1,1) Primary Key,
	CustId nvarchar(50),
	CustName nvarchar(125),
	CustType char(1)
)
create table Product
(
	Id int identity(1,1) Primary Key,
	ProdID nvarchar(50),
	ProdName nvarchar(125)
)
create table Orders
(
	OrderId int identity(1,1),
	C_Id int, -- Foreign key to Customer Id
	P_Id int, -- Foreign key to Product Id
	Units int,
	PurchaseDate date
)

For the data you included in your example you would have these values
SQL
insert into Customer values ('100JSBTM', 'Mr.James Butt','R')
insert into Product values
('1001SVST1', 'SVS1T1'),
('1001SVST2', 'SVS1T2'),
('1001SVST3', 'SVS1T3')
insert into Orders values
(1,1,5,'2016-6-15'),
(1,2,5,'2016-6-15'),
(1,3,5,'2016-6-15')

And then you would get your results table back using this query
SQL
SELECT CustName, CustId, CustType, ProdID, ProdName, Units, PurchaseDate
FROM Orders O
INNER JOIN Customer C ON O.C_Id = C.Id
INNER JOIN Product P ON O.P_Id = P.Id

Note my example is not optimised - see the links for further ideas
 
Share this answer
 
Comments
mousau 16-Jun-16 5:21am    
Hi Chill60
Seems like got to brush up the basics from tactical to practical.Thanks a lot for the help.
Regards
Moumita
CHill60 16-Jun-16 5:29am    
My pleasure. At least the articles I suggested aren't too long :-) There are others here on CodeProject too. Personally I think the MSDN article (the 3rd link) is the best to grasp the concept but the StudyTonight link (the 2nd link) has some interesting extra information that is delivered in nice bite-sized chunks

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