0% found this document useful (0 votes)
15 views

Performance DBA Example Schema

Uploaded by

Dacoda Strack
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Performance DBA Example Schema

Uploaded by

Dacoda Strack
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Alex Account TA

Double Entry Account


External Accounting Transaction SQL
Personal
• These are the steps required for the requested operations. CREATE VIEW Account_Current_V
• Person or Organisation • They are given as business Transactions;
Transactions, the DEA Credit/ AS
• Debtor or Creditor Debit pair, followed by the row. SELECT AccountNo,
TransactionType_DE • Receiver = Debit Date = DATEADD( DD, -1, GETDATE() ), -- show /as of/ previous day
XactTypeCode Giver = Credit 1.1 Alex Deposits $50 ASS.ClosingBalance, -- 1st of this month
Name TotalCredit = (
Credit 50 123 Alex SELECT SUM( Amount )
Cr Credit AccountType_Ext EntityType FROM AccountTransaction ATT
Dr Debit AccountType_Ext EntityType Debit 50 990 Liability HouseCash
WHERE ATT.AccountNo = ASS.AccountNo
Designates XactTypeCode Name AccountXact+ 990 2019.12.23 Dr Dp 123 50
AND XactTypeCode_Ext IN ( "AC", "Dp" )
Description P Person Account -- >= 1st day of this month yy.mm.01 /AND <= current date/
Fee O Organisation AccountNo 123 Alex 1.2 Alex Withdraws $75 AND DateTime >= CONVERT( CHAR(6), GETDATE(), 2 ) + "01"
Cq Cheque Cr Limits Litigation In AcccountType_Ext 234 Mary Debit 75 123 Alex ),
Sv Saving Cr LastName AK.1 345 John TotalDebit = (
SH SavingHighInt Cr FirstName AK.2 Credit 75 990 Liability HouseCash SELECT SUM( Amount )
LC LineOfCredit Dr Initial AK.3 AccountXact+ 990 2019.12.23 Cr Wd 123 75 FROM AccountTransaction ATT
Mg Mortgage Dr BirthDate AK.4 WHERE ATT.AccountNo = ASS.AccountNo
AND XactTypeCode_Ext NOT IN ( "AC", "Dp" )
Limits Transaction In BirthPlace AK.5 1.3 Day End Procedure (Batch Job, One Task)
AND DateTime >= CONVERT( CHAR(6), GETDATE(), 2 ) + "01"
BirthState AK.6
Debit 456000 990 Liability HouseCash ),
BirthCountry AK.7 CurrentBalance = ClosingBalance +
... Credit 456000 992 Liability HouseReserve
<TotalCredit> - -- subquery above
LedgerXact+ 992 2019.12.23 990 456000 <TotalDebit> -- subquery above
TransactionType_Ext Accumulates FROM AccountStatement ASS
Is Stated As 2 Charge Monthly Fee (Batch Job, One Task) -- 1st day of this month
XactTypeCode_Ext WHERE ASS.Date = CONVERT( CHAR(6), GETDATE(), 2 ) + "01"
Description foreach <AccountType_Ext> {
AC Adj Credit +
AD Adj Debit -
AccountStatement get <Fee> for <AccountType_Ext>
CREATE PROC Account_Withdraw_tr (
AccountNo @AccountNo,
Dp Deposit + @Amount
FB Bank Fee - Date
foreach <Account> IN <AccountType_Ext> { ) AS
Wd Withdrawal - ClosingBalance
TotalCredit IF EXISTS ( SELECT 1 -- validate before verb
WA ATM Withdrawal - Debit <Fee> <No> <Account> FROM AccountCurrent_V
TotalDebit
661 Revenue FeeRegular WHERE AccountNo = @AccountNo
Credit <Fee>
• One row per AccountNo per AND CurrentBalance >= @Amount -- withdrawal is possible
AccountXact+ 661 2019.12.01 Cr FB )
month, that has transactions
Internal • Date is 1st day of month <Account> <Fee> BEGIN
AccountType SELECT @LedgerNo = LedgerNo
Real AccountType
} FROM Ledger
• Balance Sheet: Description WHERE Name = "HouseCash"
Asset or Liability } BEGIN TRAN
AA Asset
• Income = Debit AL Liability INSERT AccountTransaction
3 OTC Transaction • International Transfer $500
Outgoing = Credit RR Revenue 600 RR Revenue VALUES ( @LedgerNo, GETDATE(), "Cr", "Wd", @AccountNo, @Amount )
RE Expense 660 RR Fee Debit 500 234 Mary COMMIT TRAN
Nominal GG Gain 661 RR FeeRegular END
• Profit & Loss: Ledger 662 RR FeeTransaction Credit 500 992 Liability HouseReserve
GL Losss LedgerNo
Revenue or Expense 663 RR Penalty AccountXact+ 992 2019.12.23 Cr Wd 234 500
Classifies AccountType 666 RR Adjustment
CREATE PROC Account_Deposit_tr (
Gain or Loss Name AK 890 AL House
@AccountNo,
• Expense, Loss = Debit ... Debit 500 992 Liability HouseReserve @Amount
990 AL HouseCash
Credit 500 980 Liability Interbank ) AS
Gain, Revenue = Credit 992 AL HouseReserve
... IF EXISTS, etc ... -- validate before verb
980 AL InterBank LedgerXact+ 980 2019.12.23 992 500
Dissipates BEGIN
Accumulates Accumulates SELECT @LedgerNo ...
Debit 30 234 Mary BEGIN TRAN
Is Stated As INSERT AccountTransaction
Credit 30 662 Revenue FeeTransaction
VALUES ( @LedgerNo, GETDATE(), "Dr", "Dp", @AccountNo, @Amount )
AccountXact+ 662 2019.12.23 Cr Wd 234 30
COMMIT TRAN
LedgerTransaction LedgerStatement END
LedgerNo LedgerNo 4 Transfer $100
DateTime AK.2 Date
LedgerNo_Dr AK.1 ClosingBalance Debit 100 234 Mary CREATE PROC Ledger_Xact_tr (
@LedgerNo, -- Credit Ledger Account
Amount Credit 100 992 Liability HouseReserve
• One row per LedgerNo per @LedgerNo_Dr, -- Debit Ledger Account
• One row per Xact AccountXact+ 992 2019.12.23 Cr Wd 234 100 @Amount
week, that has transactions
• LedgerNo is Cr ) AS
• Date is 1st day of week Debit 100 992 Liability HouseReserve
Internal & External • LedgerNo_Dr is Dr ... IF EXISTS, etc ...
BEGIN
Credit 100 990 Liability HouseCash
AccountTransaction SELECT @LedgerNo ...
LedgerXact+ 990 2019.12.23 992 100 BEGIN TRAN
LedgerNo
Classifies DateTime AK.2 INSERT LedgerTransaction
100 990 Liability HouseCash VALUES ( @LedgerNo, GETDATE(), @LedgerNo_Dr, @Amount )
Designates [Ledger] XactTypeCode Debit
COMMIT TRAN
XactTypeCode_Ext Credit 100 345 John END
AccountNo AK.1
AccountXact+ 990 2019.12.23 Dr Dp 345 100
Amount
CREATE PROC Account_MonthEnd_btr ( ... )
• One row per Xact AS
• XactTypeCode applies to the LedgerNo View ... begin loop
• Other side applies to AccountNo Account_Current_V Account_Month_V ... batch transaction control (eg. 500 rows per xact), etc ...
AccountNo AccountNo INSERT AccountStatement
Date OpeningDate SELECT ACT.AccountNo,
ClosingBalance OpeningBalance CONVERT( CHAR(6), GETDATE(), 2 ) + "01", -- 1st day THIS month
TotalCredit TotalCredit AMV.ClosingBalance, -- for PREVIOUS month
TotalDebit TotalDebit AMV.TotalCredit,
CurrentBalance AMV.TotalDebit
FROM Account ACT
JOIN Account_Month_V AMV -- follow link for code
Table Type Internal External ON ACT.AccountNo = AMV.AccountNo
PrimaryKey PrimaryKey Attribute
Ledger (Internal) AlternateKey AlternateKey Attribute IDEF1X Notation -- 1st day PREVIOUS month
WHERE AMV.OpeningDate = DATEADD( MM, -1, ACT.Date )
Account (External) Relational model for double entry accounting ... end loop
Transaction Wikipedia: Double-entry Bookkeeeping System ... batch transaction control, etc ...

Derek Ignatius Asirvadem • 07 Oct 2021 Copyright © 1993-2021 Software Gems Pty Ltd [A3 Ld 100] Alex Account TA • 1 of 1

You might also like