r/DatabaseHelp • • Jun 17 '18
Double-Entry Accounting
I've been reading "Enterprise Model Patterns" to try to understand more about business databases and accounting, but I'm struggling a bit with what a real double-entry accounting database should look like in practice.
I've started a fiddle here: SQLDBM Accounting Test
If I understand the text, Account should be a super-type, with Assets, Liabilities, etc., being sub-types - which to me translates as 1-to-1 relationships.
Once it gets to balances and transactions, though, I'm pretty sure I have the relationships and keys messed up. It seems like it wouldn't be any different than a line item on an order or invoice, but the sequential nature of immutable accounting is throwing me for a loop.
I've been trying to find a good example schema or diagram - they seem to be extraordinarily rare...at this point, I'd be ready to buy another book if it happened to cover accounting databases in detail.
Any help or examples would be appreciated. I feel like if I saw a working model I'd be able to wrap my head around it. Many thanks in advance.
View all comments
Show parent comment
2
u/wolf2600 Jun 17 '18 edited Jun 17 '18
Transaction table would be just like I had it above.
TxnID AccountID Date Desc TxnType Amount0001 4401 2018-05-01 Payroll D -100.000024 2332 2018-05-01 Payroll C 100.000414 4401 2018-05-01 Embezzlement D -500.000414 1234 2018-05-01 My Pocket C 500.00Where Account 4401 would be your Cash Asset account and Account 2232 would be Payroll Expense. (or something like that).
To get the account balance it would probably require something like Starting / Ending balance entries at the start/end of each month. +Starting Amount as the first entry of the month/quarter/year/etc, and -Ending Amount as the last entry when you close out the period.
Then you can just run a query on the Transactions table to sum up all transaction for the period to get the current balance:
TxnID AccountID Date Desc TxnType Amount0000 4401 2018-05-01 OpeningBalance C 35352.350001 2232 2018-05-01 OpeningBalance C 9752.120007 4401 2018-05-01 April_Payroll D -100.000007 2332 2018-05-01 April_Payroll C 100.000024 4401 2018-05-31 ClosingBalance D -35252.350025 2232 2018-05-01 ClosingBalance D -9852.12The Transactions table would look just like a traditional paper general ledger.