Unix Technical Forum

SQL Query Help - - Table Normalization

This is a discussion on SQL Query Help - - Table Normalization within the SQL Server forums, part of the Microsoft SQL Server category; --> hello I've a denormalized table PRODUCTS with following fields: ProductNo , OrderNo , SerialNo , OrderDate , PromiseDate , ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 04:31 AM
Muzamil
 
Posts: n/a
Default SQL Query Help - - Table Normalization

hello

I've a denormalized table PRODUCTS with following fields:


ProductNo ,
OrderNo ,
SerialNo ,
OrderDate ,
PromiseDate ,
ManufacturerID ,
..
..
..
DistributorID ,
DealerID ,
..
..
..
ReceiptDate ,
..
..
..


I have to denormalize this table, so I created 3 tables:

Table Name : ProductOrders
Fields:
+ProducrOrderID,
ProductNo ,
OrderNo ,
SerialNo ,
OrderDate ,
PromiseDate ,
ManufacturerID ,
-------------------------------
Table Name: ProductsOrdersDetails
Fields:

+ProductsOrdersDetailsID,
ProductOrdersID,
DistributorID ,
DealerID
..
..
..
-----------------------
Table Name: ProductsOrdersReceipts
Fields:
+ProductsOrdersReceiptsID,
ProductsOrdersDetailsID,
ReceiptDate ,
..
..
..

----------------------------

DistributorID and DealerID appear in Details table because a
particular order number for a specific product number can come from
different distributor and dealer.


What I need is a query to populate these normalized tables from the
original denormalized Products table.

Can any one please help?

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 04:32 AM
Erland Sommarskog
 
Posts: n/a
Default Re: SQL Query Help - - Table Normalization

Muzamil (muzamil@hotmail.com) writes:
> I have to denormalize this table, so I created 3 tables:
>
> Table Name : ProductOrders
> Fields:
> +ProducrOrderID,
> ProductNo ,
> OrderNo ,
> SerialNo ,
> OrderDate ,
> PromiseDate ,
> ManufacturerID ,
> -------------------------------
> Table Name: ProductsOrdersDetails
> Fields:
>
> +ProductsOrdersDetailsID,
> ProductOrdersID,
> DistributorID ,
> DealerID
> .
> .
> .
> -----------------------
> Table Name: ProductsOrdersReceipts
> Fields:
> +ProductsOrdersReceiptsID,
> ProductsOrdersDetailsID,
> ReceiptDate ,
> .
> .
> .


I think you should find the real keys of your subtables. If I understand
your narrative correctly, the primary key for ProductOrderDetails
should be (ProductOrderID, DistributorID, DealerID). In the same vein
the key for ProductsOrdersReceipts should maybe be
(ProductOrderID, DistributorID, DealerID, ReceiptDate).

In the long run this will make the data model easier to understand,
and easier to query.

> What I need is a query to populate these normalized tables from the
> original denormalized Products table.


Without the complete CREATE TABLE statements and sample data this
is somewhat difficult. But I would guess that for the first two
tables, you would have to use the DISTINCT keyword. But it will be
all straight-forward. At least if you follow my recommendation on the
keys.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:37 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com