简体   繁体   English

数据库设计:会计交易表

[英]Database design: accounting transaction table

Storing the transaction entry into a double entry accounting database. 将事务条目存储到双条目记帐数据库中。

I came up with two solutions option 1 and option 2, I was told most banking package chooses option 2 for their database design. 我提出了两个解决方案选项1和选项2,我被告知大多数银行包选择其选项2进行数据库设计。 However I prefer option 1 over option 2 because it simply makes sense and it is more efficient! 但是我更喜欢选项1而不是选项2,因为它只是有意义而且效率更高!

Ie For the 2 movement of funds, option 1 requires 2 records vs option 2 requires 4 records. 即对于资金的2次移动,选项1需要2个记录而选项2需要4个记录。

I would like to know why the bank would choose option 2 over option 1? 我想知道为什么银行会选择2而不是选项1? what is the reason for this? 这是什么原因?

Option 1)
TRANSACTION
Credit_AccountId
Debit_AccountId
Amount
...

Option 2)
TRANSACTION
AccountId
Amount
...

Option 1 will potentially be a bit more efficient from an insert perspective. 从插入角度来看,选项1可能会更有效。 But since a lot of accounting transactions are going to affect more than two accounts, the benefit is likely to be substantially less than 2:1. 但由于很多会计交易将影响两个以上的账户,因此利益可能远低于2:1。

Option 2 will be clearer for these more complex transactions. 对于这些更复杂的交易,备选方案2将更加清晰。 That is, an accountant would normally find three rows 也就是说,会计师通常会找到三行

  • Debit A $100 借记100澳元
  • Credit B $60 信用B $ 60
  • Credit C $40 信用C $ 40

more clear than two rows 比两行更清晰

  • Debit A $60 Credit B $60 借记A $ 60信用B $ 60
  • Debit A $40 Credit C $40 借记A $ 40积分C $ 40

If you have multiple accounts on both sides, it would also be a bit unclear how to match up the debits and credits to a single account. 如果您双方都有多个帐户,那么如何将借方和贷方与单个帐户进行匹配也会有点不清楚。 That is, 那是,

  • Debit A $100 借记100澳元
  • Debit B $30 借记B $ 30
  • Credit C $60 信用卡C $ 60
  • Credit D $70 信用D $ 70

could be represented as 可以表示为

  • Debit A $60 Credit C $60 借记A $ 60积分60加元
  • Debit A $40 Credit D $40 借记A $ 40积分D $ 40
  • Debit B $30 Credit D $30 借记B $ 30积分D $ 30

but there are also other possible ways to construct the data for data model 2. 但是还有其他可能的方法来构建数据模型2的数据。

Additionally, option 2 is going to be more efficient if you're trying to determine the current balance of a particular account by aggregating the transactions. 此外,如果您尝试通过聚合交易来确定特定帐户的当前余额,则选项2将更有效。

In a general accounting database design, it is logical and efficient to store your debits and credits in a single fields (ie option 2), as this would simplify aggregation,number manipulations and reporting. 在一般会计数据库设计中,将借方和贷方存储在单个字段(即选项2)中是合乎逻辑且有效的,因为这将简化汇总,数字操作和报告。 There should be a datetime field attached to each debit and credit transactions to filter out a particular period. 每个借记和贷记交易都应附加一个日期时间字段,以过滤掉特定时期。 Get the book from Smashwords, titled, accounting database design. 从Smashwords获取这本名为“会计数据库设计”的书。 It provides some good samples on accounting system design and some interesting sql query for financial reporting. 它为会计系统设计提供了一些很好的样本,并为财务报告提供了一些有趣的sql查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM