views:

108

answers:

3

Simple question- Below 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. :)

A: 

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.

Don Dickinson
A: 

The design is good and normalized.

Put more details..!!

pvaju896
+2  A: 

At the first glance it looks ok.

alt text

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.

alt text

Damir Sudarevic
+1 for the nice diagram but what happen to the FeeTransaction ID? (your redesign could determine related transaction just like the original design, this is ok, however it now no longer tell me where I can locate the fee transaction record).
K001
LinkedTransactionID can be the FeeTransactionID or RefTransactionID -- depending on the TransactionTypeID.
Damir Sudarevic