I would personally consider the open / close principle in OOP and apply it to the DB in a similar way. It might break some normalisation rules (im not sure) but it goes like this.
Create a battery table with the fields you want that are common to the other tables.
Next create a new table for each sub-type of battery.
Then link each sub table with the base table using a one to one relationship.
By specifying the relationship cascading rules right, you will not have to use triggers or views so all your code is obvious.
It does mean you will have to use joins to get at all the data but I dont see that as breaking any big bad rules. To me its logical as two tables are involved, so you create a join when needed.
Note: Im not suggesting there is anything wrong with triggers or views approach as recommended here. I just wanted to put an alternative forward.
I would welcome any suggestions on the pros and cons of this over other ideas as I am learning too. Thanks.
No comments:
Post a Comment