数据库设计:有没有办法改进这个设计?

发布于 2024-09-08 05:36:02 字数 901 浏览 1 评论 0原文

简单的问题 - 下面是保存以下记录的数据库设计

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

[Transaction]
Id
AccountId 
TransactionTypeId
TransactionName
Amount
FeeTransactionId
RefTransactionId

[Account]
Id
Name

[TransactionType]
Id
Name

有没有办法改进此设计?

注意:缺少货币和日期。 :)

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. :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撧情箌佬 2024-09-15 05:36:02

乍一看还不错。

transaction_model_02

经过一番考虑,似乎每笔交易都链接到一个(且只有一个)其他交易,并且该链接的含义取决于交易类型。因此有两个自引用外键 FeeTransactionIdRefTransactionID。根据交易类型,这些键之一始终为 NULL。

尽管在技术上可以在外键列中包含 NULL,但它可能不是首选做法。您只能有一个自引用外键,该外键不会有 NULL,如本模型所示。

transaction_model_03

At the first glance it looks ok.

transaction_model_02

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.

transaction_model_03

流殇 2024-09-15 05:36:02

设计很好。很好而且标准化。不过,去规范化可能有充分的理由。通常这些涉及某种报告便利性或优化。如果没有有关该项目的更多详细信息,我真的无法提出任何更改建议。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文