You need to read up on DBMS Design theory. Specifically
what they call "Database Normalization". Not understanding
the basics of DBMS theory is likely to result in painting yourself
into a corner. DBMS system have a way of starting out simple and then growing. Starting with a fully normalized design means that you can
grow the application without needing to start over.
Use Google to find "Database Normalization"
but one refference is
http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html
Your suggestion amounts to a kind of "anti-normalization". About the last thing you'd want to do.
Do not be afraid of doing Joins. the Join operation is the whole reason
we use _relational_ databases, because they enable Joins.
One "Red Flag" in any DBMS design is when you find that your code needs to make one query, hold a result from it and use that result to make a second query where the result of the second querry is really what you want. A design such as that will break due to concurrentcy or if you try to use locks it will not scale and could evn rsult in deadlocks unless yu understand theory related to deadlock prevention and detection.
The second "Red Flag" is any design that stores the same information twice
Like spliting the table as suggested.
OK Put all the above into use:
You need to make several tables
(1) A Parts table. It will have one row for each part. The primary key is "part_number"
(2) An "Order Table" it has one row for each order. Primary ket is "order number"
(3) An Oder Detail table. This has two colums "order number" and "part number"
The above design is a "clasic" used in many text book examples
You can extend it to include a "customer" table and an "saleman" table
and so on.
A good "rule of thumb" in DBMS design, if you don't want to bother with formal normalization theory is to make a table row represend ONE (and one ONE) object or event. for example a prt or a transaction or a person. You table does not do this. It describbes a part AND when it was ordered. So it is not surprize that the only way to querry the info you anted was to join to subsets of the table together.
.
what they call "Database Normalization". Not understanding
the basics of DBMS theory is likely to result in painting yourself
into a corner. DBMS system have a way of starting out simple and then growing. Starting with a fully normalized design means that you can
grow the application without needing to start over.
Use Google to find "Database Normalization"
but one refference is
http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html
Your suggestion amounts to a kind of "anti-normalization". About the last thing you'd want to do.
Do not be afraid of doing Joins. the Join operation is the whole reason
we use _relational_ databases, because they enable Joins.
One "Red Flag" in any DBMS design is when you find that your code needs to make one query, hold a result from it and use that result to make a second query where the result of the second querry is really what you want. A design such as that will break due to concurrentcy or if you try to use locks it will not scale and could evn rsult in deadlocks unless yu understand theory related to deadlock prevention and detection.
The second "Red Flag" is any design that stores the same information twice
Like spliting the table as suggested.
OK Put all the above into use:
You need to make several tables
(1) A Parts table. It will have one row for each part. The primary key is "part_number"
(2) An "Order Table" it has one row for each order. Primary ket is "order number"
(3) An Oder Detail table. This has two colums "order number" and "part number"
The above design is a "clasic" used in many text book examples
You can extend it to include a "customer" table and an "saleman" table
and so on.
A good "rule of thumb" in DBMS design, if you don't want to bother with formal normalization theory is to make a table row represend ONE (and one ONE) object or event. for example a prt or a transaction or a person. You table does not do this. It describbes a part AND when it was ordered. So it is not surprize that the only way to querry the info you anted was to join to subsets of the table together.
.
MarkCollette said:I guess I could split the PartOrders table into HistoricalPartOrders and LatestPartOrders, and do INSERTs into HistoricalPartOrders and UPDATEs into LatestPartOrders. But that sounds like it's have a bunch of tradeoffs, and I'd have to do a query from both to get all the data out.
Anyways, I still have to try out everyone's suggestions (had to fix some other code first).