Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

table and relationship structure

Status
Not open for further replies.
Oct 23, 2002
110
US
I have been tasked to develop a database that tracks departmental sales per day and location. I am having some trouble setting up the initial tables. I have a customer count that applies to the day only, then I have sales figures for each of 12 locations for each department (10) for every day. Which data\fields do I place in which table? Anyone have any ideas?
 
Usually its
[tt]
SaleHeader

SaleNumber
SaleDateTime
Location
... Other Info About the WHOLE Sale ...

SaleLines
SaleNumber
LineNumber
ItemSold
Department
Quantity
Price
[/tt]
and then
Code:
Select Department, Sum(Quantity*Price) As [Sales]

From SaleHead H INNER JOIN SaleLines L
     ON H.SaleNumber = L.SaleNumber

Where H.SaleDateTime Between [Enter Start Date] AND [Enter End Date]

Group By Department
will give you the sales by department for some date range.
 
The client is looking for something at a higher level. They do not want individual transactions in the DB. They just want a sales number for every store, location, and department that shows total daily sales. There are no items or transactions in the DB. My question is do I create a different table for every location or do I lump all sales into one table and make the date, location, and department the primary key?
 
OK ... but where does the data come from to supply those values?

At some level they are doing individual sales and the mechanism to roll up sales by department or by location must involve the sort of calculations that I illustrated above. If someone is doing all that manually and just entering the data after it is cumulated then the structure that you suggest would probably work.

I would use one table with location as one of the columns and the primary keys would be as you suggest ... Date, Location & Department. Multiple tables make it very challenging to answer questions like "Which Location had the Highest Sales in Department 10 on July 7?" but that's simple if Location is just another column.
 
No. The sales numbers are an attribute of the date which includes Day, Month and Year. Splitting into multiple tables for each year raises the same problems that splitting into different tables for each Location does.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top