Table layout help required!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • VinylMatt
    New Member
    • Jul 2006
    • 1

    Table layout help required!!!

    This might be simple or it might not...

    I've got a table which stores items of equipment. Some items of equipment need servicing and they might need more than 1 type of service. So far I've come up with:

    Table Name: [Equipment], PKey: [ItemID], Other fields as appropriate...
    Table Name: [ServiceType], PKey: [ServiceTypeID], Description, Frequency
    Table Name: [Service], PKey: [ServiceID], FKey: [ItemID], FKey: [ServiceTypeID]

    Now what I want to do is store the results for each type of service in its own table (each service type will have different checks and therefore different results):

    Table Name: [ServiceResultsF orServiceTypeID 1], PKey: [ServiceResultsI D], FKey: [ItemID], DateTested, Results as appropriate...

    Table Name: [ServiceResultsF orServiceTypeID 2], PKey: [ServiceResultsI D], FKey: [ItemID], DateTested, Results as appropriate...

    Now how do I join these result tables to the rest of the database? I thought about storing the table name for the results in a field in the ServiceType table but don't see how this'll work.

    I hope I'm clear enough - let me know if this doesn't make sense.
    Thanks in advance,
    Matt.
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    1st. what is the reationale of having a separate 'ServiceResults ForService' tabel for each servicetype?
    2nd I have no intention of patronizing, but let's make it easier and visualise the tables involved. That way it is easier to see relations and connections between tables and keys. Example:
    Code:
      Equipment         ServiceType             Service               Service Results
    +-----------+    +---------------+    +---------------------+    +------------------+
    | ItemID    |    | ServiceTypeId |    | ServiceId           |    | ServiceResultsId |
    |  PKEY     |    |   PKEY        |    |  PKEY               |    |    PKEY          |
    |-----------|    |---------------|    |---------------------|    |------------------|
    | other ... |    | Descr, freq...|    | ItemId        FKEY  |    | ItemId    FKEY   |
    |-----------|    |---------------|    |---------------------|    |------------------|
    |           |    |               |    | ServiceTypeId FKEY  |    |                  |
    |-----------|    |---------------|    |---------------------|    |------------------|
    |           |    |               |    |                     |    |                  |
    +-----------+    +---------------+    +---------------------+    +------------------+
    Now you are able to draw (with a pen) those connections. If you cannot connect a table to any of the other ones, you must insert a field in that table that will make that possible.

    Get back when you are done.

    Ronald :cool:
    Last edited by ronverdonk; Jul 21 '06, 05:08 PM.

    Comment

    • comteck
      New Member
      • Jun 2006
      • 179

      #3
      Just two question.
      1. What data type are you using for your Primary Keys and Foreign Keys in each of the tables?
      2. What kind of relationship is set up between the tables?

      comteck

      Comment

      • cleaner7777
        New Member
        • Mar 2006
        • 7

        #4
        Just a guess... but you might try creating a view on top of all of your tables.

        CREATE VIEW ServiceResultsF orServiceType as
        (SELECT * FROM ServiceResultsF orServiceTypeID 1)
        UNION
        (SELECT * FROM ServiceResultsF orServiceTypeID 2)
        UNION
        ...
        UNION
        (SELECT * FROM ServiceResultsF orServiceTypeID n)

        Comment

        Working...