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:
Sorry for the bad description...I really wish I could attach my diagram... A picture is worth a thousand words..
答案 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.