I'm designing a database where I need to store paid orders and unpaid orders of a customer. Both categories of orders have same attributes and relationships with other tables.
I have come up with two designs:
1. Separate tables for the two categories of orders:Pros: This design helps me to quickly differentiate between the orders in cart and those which are paid. Whenever a customer revisits my website, I just need to lookup the UnpaidOrder table for that particular customer and my cart is ready.
Cons: Whenever the payment for an order in UnpaidOrder table is made, I need to move the corresponding rows (of UnpaidOrder and other tables linked with it) to PaidOrder table and its corresponding tables. Also this design will require 2x number of tables: eg. UnpaidOrderDeliveryAddress, UnpaidOrderCreditCard, ... for relationships with UnpaidOrder and PaidOrderDeliveryAddress, PaidOrderCreditCard, ... for PaidOrder.
2. Common table for both categories and an extra Status attribute:Pros: I don't need to move multiple rows on payment of an unpaid order. Also, the number of tables for corresponding relationships is halved.
Cons: I'm storing an extra Status attribute for each row. Whenever a customer revisits my website, I need to lookup the Order table and I need to check the Status attribute (paid/unpaid) of each row for that particular customer. As a result, the cart will take a longer time to load.
My questions are:
Another Opinion....
There is no need for extra normalization tables (UnpaidOrderDeliveryAddress, UnpaidOrderCreditCard, ... for relationships with UnpaidOrder and PaidOrderDeliveryAddress, PaidOrderCreditCard, ... for PaidOrder). If you argue that FOREIGN KEYs
need such, I will argue against using FOREIGN KEYs
in such situations. Simple indexes will suffice.
Since you will eventually have far more "paid" entries than "unpaid" entries, and paid entries are essentially 'history' that you rarely need to touch, I lean toward 2 tables.
I probably would not use a Trigger -- I would rather do it in application code where I have more control.
Are you expecting more than 100 SQL statements per second to be executed? If not, I would not call it "heavy".
Be sure to carefully surround appropriate groups of statements with BEGIN..COMMIT
. Also, use FOR UPDATE
on SELECTs that are leading to UPDATEs.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments