I’m a junior programmer and particularly novice at database design.
A while ago in my spare time i created a program to track and graph share price changes in java. At the time i couldn’t be bothered installing a DB for it, so it just used a pile of CSV files to store the data, one of each stock being tracked (e.g GOOG.csv, BHP.csv ).
Iv’e decided to update it to use a database as a learn activity, but in my design i hit a hurdle.
Should i continue my previous design of separate data piles for each stock or integrate them. That is to say, should i have a table per tracked stock, with a new record for each days data, or should i have a generic “Stock data” table with a identifier for the stock.
The first seems more straight forward, getting all the records would be as simple as
SELECT *
FROM GOOG
Where as the 2nd would be
SELECT *
FROM stock_data
WHERE stock_name="GOOG"
Like i said, i’m a total database novice. To me, the first seems like it would be faster, but an overall a poor and hard to manage design, that wouldn’t scale well.
The 2nd seems like it might be needlessly slow if the first is fine.
I realize that due to the scale of my project, either would likely work fine, but as a rule for this type of problem, which would be the correct design choice?
Any sage DB design advice welcome. 🙂
By chance, I too wrote a similar program to track my own investments. A suitable schema would be
The primary key of the prices table would be stock + curdate.
If you want to track purchases, sales, dividends and costs then you will need at least one more table (if not two). Most of my investments are in bonds with complicated redemption schemes, so I have a few special tables for them as well.