开发者

Database design: Is there a way to improve on this design?

Simple question- Belo开发者_如何学JAVAw is the database design to hold the following records

account     TransactionType     TransactionName                 Amount      FeeTransactionId    TransactionId   RefTransactionId

Alex        [Deposit from]      [Credit Card x-1234]            [-100.00]               b           a   
Alex        [Deposit from]      [Credit Card Fee]               [-3.00]                             b           a
Alex        [Added funds from]  [Credit Card x-1234]            [100.00]                            c           a
Sys_        [Revenue from]      [Credit Card Deposit]           [3.00]                              d           a

the design

[Transaction]
Id
AccountId 
TransactionTypeId
TransactionName
Amount
FeeTransactionId
RefTransactionId

[Account]
Id
Name

[TransactionType]
Id
Name

Is there a way to improve on this design?

Note: currency and date is missing. :)


At the first glance it looks ok.

Database design: Is there a way to improve on this design?

After some consideration, seems that each transaction is linked to one (and only one) other transaction, and that the meaning of that link depends on the transaction type. Hence the two self-referencing foreign keys FeeTransactionId and RefTransactionID. Depending on type of the transaction, one of these keys is always NULL.

Altough it is technically possible to have NULLs in a foreign key column, it may not be preffered practice. You could have only one self-referencing foreign key, which would not have NULLs, as in this model.

Database design: Is there a way to improve on this design?


The design is fine. Nice and normalized. There can be good reasons to de-normalize, though. Usually these involve some sort of reporting convenience or optimization. Without more details about the project, I really can't make any sort of recommendations for changes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜