I am writing an application for Android using SQLite (backed by ORMlite if it matters). So far I'm in the conceptual stage and working on the database design. The database is being designed to contain a collection of assets that are registered to one or more users. I have never worked on any data outside of SQLite and even then I have only made a few very small databases. As such I am not sure that my I handling this design correctly. As I expand on my design, it is beginning to look like a mess. My questions are:
- Am I designing this database in too much of an ObjectOriented fashion? As a java programmer, this is just how it makes sense to design the database.
- Is there any way to make the database look less like a mess?
- Am I even on the correct track?
For reference here is an earlier more easy to read protoype of the database design. No typings have been assigned yet, sorry.
The previous database design
Here is a more updated visualisation of my problem.
The current database design
1 Answer 1
This is more of a comment, but since this is a lengthy response that's worth mentioning, I'm posting it as an answer.
Your database looks sufficient for your needs. (Well, as best can be assumed from the diagram.) I assume that the UserAccount
table has a one-to-many relationship between the four tables Vehicle
, Book
, VideoGame
and Movie
(from here on, the V-B-V-M tables.) Next, I assume that the Asset
table has a one-to-one relationship with each link between the V-B-V-M table entries. With this information, I would recommend moving the UserAccount_id
from each V-B-V-M table, to the AssetTable
.
Next, it seems that Asset
is always associated with one of the four V-B-V-M tables. Considering this type of setup, I would recommend creating an additional table-- AssetType
.
+-----------+
| AssetType |
+-----------+
| id |
| typeDesc |
+-----------+
Next, update the Asset
table and each V-B-V-M tables to include a AssetType_ID
field. the AssetType
table should include one entry, for each type of asset. In this case, Vehicle
, Book
, Video Game
and Movie
, each with a unique description and ID.
You may want to do this for a couple reasons-- First, you can now query the Asset
table and discern what type of asset is stored in a specific record, without having to link the data to your four other V-B-V-M tables. This will speed up your querying of the data, when all of the information from your four tables isn't needed. Second, this also provides an easy means of linking in a textual description of the type of asset associated with the Asset
entry. Again, without having to link to the V-B-V-M tables to figure that out.
Last, you may want to consider handling the barcode data differently. If barcode is a simple look-up, you can add it to the asset table. However, if barcode values have to be unique, keeping it in a secondary table is necessary because you'd have to put a constraint on the database. You could do this if it was integrated in the Asset
table, however, your vehicle data would cause problems because vehicles do not have barcodes. To my knowledge most, if not all, major database engines won't allow you to define a unique field, that also allows null
values because, then, the data is no longer unique.
You might be inclined to think that you could combine the Barcode
field with the VIN
. Since VINs are unique and Barcodes are unique, and neither should be the same, why can't they be combined into one field on the Asset
table, which allow you to drop the additional Barcode
table. I wouldn't recommend this because I think it gives the data less "focus".
Yes, it is a form of unique object ID but barcodes are barcodes and VINs are VINs-- the concept behind both is completely different and consolidating the two can become confusing with time. Furthermore, if you expand your project in the future, it could cause collisions. Technically, I don't see a big problem with that (in your case) but I'd still highly recommend avoiding that option.
Also, I would also add the assetType_id
to the Barcode
table, for the same reasons you added it to the Asset
table.
-
Thank you for the lengthy and complete answer. I acutally had just done most of that right before your answer posted. After the comments and consulting the hierarchical wiki again, it seemed like the best and most logical idea. I, however, did not think of adding the asset_type. That also makes an abundant amount of sense.ahodder– ahodder2012年07月24日 17:43:26 +00:00Commented Jul 24, 2012 at 17:43
-
@AedonEtLIRA: Yeah, I hadn't seen your update while typing up the answer. I would recommend moving the
Barcode
data to thePublication
table, unless you expectBarcode
to account for multiple instances of a publication. Is the barcode specific to a single object, or is this something like an ISDN?RLH– RLH2012年07月24日 17:45:49 +00:00Commented Jul 24, 2012 at 17:45 -
I have considered moving
Barcode
to publication. The more I think about it, the more it makes sense to be in there. ABarcode
is not guaranteed to be unique. Someone could have multiple instances of an asset. Where would we be if (s/h/it) wanted to keep track of each? Then again, I could have a field in theAsset
table for quantity. Thanks again.ahodder– ahodder2012年07月24日 17:52:23 +00:00Commented Jul 24, 2012 at 17:52
messy
is actuallynormalization
which is ordinarily a good thing.