Reputation: 65147
Which design would you choose for a database for the custom fee table and why?
Option 1) 1 table, UserId determines if user has custom fee
ACCOUNT_FEE
TypeId
FixedRate
VariableRate
CurrencyId
UserId (UserId is null for default account fee, UserId is present for custom fee)
Option 2) 2 separate tables, one for default fee the other for user's custom fee
ACCOUNT_DEFAULT_FEE
TypeId
FixedRate
VariableRate
CurrencyId
USER_ACCOUNT_FEE
TypeId
FixedRate
VariableRate
CurrencyId
UserId
Upvotes: 0
Views: 352
Reputation: 3523
I would recommend the single table approach for the custom fees which means you can add more custom fees as they may be needed.
An additional enhancement - consider adding an effective and expiry date to the fee so that is easy to find out when the custom fee is active and allows the useage of additional fees for specific periods of time
Upvotes: 0
Reputation: 107716
I would do it differently. Create a user called "Default Account" and give it a specific ID, or even "0" (identity_insert may be required). This allows the table to follow referential integrity rules AND the index on UserID can quickly pick out the Default Account Fee.
Otherwise,
Upvotes: 1
Reputation: 35374
I would choose the first design, for the following reasons:
No need to change two tables as the design evolves.
Front-end CRUD code only needed for one table.
Getting a customer's "correct" fee of a particular type is simple:
SELECT TOP 1 * FROM ACCOUNT_FEE
WHERE
(UserId=333 OR UserId IS NULL)
AND TypeId=2
ORDER BY UserId DESC
Upvotes: 0