Question NEEDS Help

  • Hi,

     i need help on this . i have to create Tables with the following information below in a relational Database.Can somebody explain me me how many tables do i need to create and which one .

     

     

     

    Electricity
     2004  2005  2006 
             
    UsageDemandTotal CostUsageDemandTotal CostUsageDemandTotal Cost
    Jan         
    Feb         
    Mar         
    April         
    May         
    June         
    July         
    August         
    Sept          
    Oct         
    Nov         
    Dec         

     

    Fuel 
    2004 2005 2006 
          
    Gallon DeliveredTotal CostGallon DeliveredTotal CostGallon DeliveredTotal Cost
    Jan      
    Feb      
    Mar      
    April      
    May      
    June      
    July      
    August      
    Sept       
    Oct      
    Nov      
    Dec      

     

  • How many records do you anticipate having? 10's or Millions?

    How will you be using the data?

    Do you have any requirements that you can pass along?

    Your needs will dictate the solution.

  • The information above shows For example electricity cost for  three year for every month and thats it.That is all information i have .

  • If you are only talking about your electric bill, then just use a spreadsheet.

    I really do not understand what you are asking.

  • You need one table for the gaz and one for the electricity.

     

    The basic format will look like this :

    clientID, ReadDate, Quantity, CostPerUnit (can be in another table with cost, datefrom and dateto, but it adds another join on the report which can be a bottleneck).

     

    Then you basically build a proc that groups the data by month of the year and clients.  As it's already been said, you might have to create reporting tables where you will ship the data once and keep for history and reporting sake.  Or if you have very little data, then you can recalculate on the fly everytime.  Both method works, it's just up to you to decide wether you want to spend more time on developping the system, or having the server work more.  This will depend solely on the amount of data and the amount of reporting required of that data.  I can't help you much on that at this point because I don't have any figures to go by.

  • OK,

      I guess it is getting ConFUSING. let me tell you the solution and i just want to know whether iam on the right track or not.

    Inthis case what iam doing is .

    iam creating the following tables

    Month_Table  --------which has the months from jan-dec

    Year_Table --------which has years from 2004-------2006

    Category_Table------Which has the following two categories Electricity,Fuel oil

    Electricity_Table-----which has information such as usage,demand,Total cost e.t.c

    Fuel oil_Table--------which has information such as Gallon Delivered,Total Cost

    does this makes a little clear what iam trying to ask?(becz Relational database)

  • Month and year table are usefull to do a left join so that months and years without data can still be displayed.  The category table doesn't make much sens to me because the Electricity and fuel tables are seperated (any other data you are not sharing with us).

     

    What's left to do is decide if you want to have permanant reporting tables which hold the calculated results from the queries that create the reports.  This will hold the answer as to whether you need another set of 2 tables or not (you don't need one per year, just keep the year in a column in the report, making it part of the clustered index along with the month).

  • Please remember we are not playing Jeopardy here, where you give the solution and we guess what the problem is.

    If you want the proper help you will have to tell us what the PROBLEM is, not what the SOLUTION needs to be.

    Do you have to store data about your customers Electricity or Fuel Oil usage?

    What details about each customer will you need to track? What would comprise a singular record?

    What is the scale (how many rows) are you looking to store?

  • You need 4 tables:

    Table dbo.Calendar to hold all possible dates;

    CREATE TABLE dbo.Resource (

    ID smallint IDENTITY(1,1) NOT NULL RPIMARY KEY,

    Name nvarchar(100) NOT NULL

    )

    to hold the list of resources you manage (currently "Electricity" and "Fuel");

    CREATE TABLE dbo.UOM (

    ID smallint IDENTITY(1,1) NOT NULL RPIMARY KEY,

    Name nvarchar(100) NOT NULL

    )

    to hold all units of measure, including money currencies;

    CREATE TABLE dbo.Usage(

    ResourseID smallint NOT NULL,

    DateUsed datetime NOT NULL,

    Demand DECIMAL (18, 4) NULL,

    UOM_ID smallint NOT NULL,

    Price money NOT NULL,

    CurrencyID smallint NOT NULL,

    Usage DECIMAL (18, 4),

    TotalAmount AS CONVERT(money, Price * Usage )

    )

    Then you need single table function which will take @ResourceID, @DateFrom, @DateTo as parameters and return aggregations for the period.

    _____________
    Code for TallyGenerator

  • Spot on, Serqiy!

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply