MS-Access: Table entry can have different properties based on it's type

时间:2015-07-28 22:09:48

标签: ms-access ms-access-2010

First off A little background: I took over a position that tracks a lot of data through different excel sheets and currently it's an absolute mess and a nightmare to track and go through. This will be for personal use just to assist with my job and I want to make a simple database in access just to clean up the data and store it in a proper format (as it should have been in the first place). I'm fairly happy what I have so far but just got stuck on one last design element.

I've tried to read up on the problem but since I don't have a lot of background in this it's hard for me to find the term to read up on (learning as I go) and it's a little hard to describe.

So my question is regarding database design; what's the proper way to handle a table that can have different values based on it's type

In my table, for example, I need to track Purchase Orders; A purchase order has details; and these details are made up of MANY assets. The Assets can be one of 3 things: Workstations, Software, Hardware (each with their own properties).

As mentioned I'm learning as I go and I have read up on key concepts before I started and was going smoothly until now. I'm obviously missing something so any help in the right direction would be helpful

I'd attach my Diagram but since my reputation is not high enough I am unable to do so. so more detail:

  1. I have a Table PURCHASE_ORDER that has pretty much all info needed in regards to a PO:
    • PO_Number (PK, Purchase order number)
    • PO_Vendor (FK, not related to the problem I'm having)
    • PO_SubmittedBy (FK, not related to the problem I'm having)
    • PO_SubmitDate (not related to the problem I'm having)
    • PO_ReceivedDate (not related to the problem I'm having)
  2. PURCHASE_ORDER_ITEM has the fields:
    • POI_ID (PK, auto-increment)
    • POI_Asset (FK, Required, Asset that makes up the line item)
    • PO_Number (FK of Purchase_Order ID, Required, ties the line item to the PO)
    • POI_Qty (not required, just quantity of the item ordered)
    • PO_UnitPrice (not required, price per unit)
  3. The relationship between Purchase_Order and Purchase_Order_Item is one to many (one purchase order can have many Purchase order Items).
  4. This is mainly where my problem is: The ASSET table; the details of the POI_Asset found in PURCHASE_ORDER_ITEM. An Asset can be one of 3 types: Workstations, Hardware, or Software and each of those have different table properties. I put any common info they share in the asset table however the unique info in different tables (WORKSTATION, HARDWARE_TYPES, SOFTWARE) I wanted to split them into different tables as I didn't want to have a whole bunch of empty fields and redundant info. I run into the problem though the single field in ASSET (A_EquipmentType) can't reference 3 different tables (obviously). How would I direct it to look for the right table?

Sorry for the bad description...I really wish I could attach my diagram... A picture is worth a thousand words..

1 个答案:

答案 0 :(得分:0)

What about the following table structures?

Assets
--------
AssetID (PK)
EquipmentTypeID
(other fields common to all assets

Workstation
-----------
AssetID (PK, one-to-one join to Assets.AssetID)
(workstation-specific fields)

and repeat for the Hardware and Software tables. I think this would be enough for most scenarios, as you can't have the same AssetID on two records in single table.

It's still possible that the same AssetID will appear in multiple tables: e.g. both Workstations and Software could each have a single record with a given AssetID. If this is a concern, you could add an EquipmentTypeID field to each of the detail tables, and restrict the value of EquipmentTypeID to the value for that table (for Hardware it could only be the ID for hardware, etc.). Next, the joins between the tables should include both AssetID and EquipmentTypeID. Then, it would be impossible to have multiple detail records for a single asset, even across multiple tables.