Software Development · Pune, India
Back to Blog
20 Nov 2026 · By Mayur Kadam · M-Tech Systems IT Services

Designing a Double-Entry Financial Ledger Schema in SQL: Debits, Credits & Audit Trails

When business applications track customer invoices, vendor expenses, wallet top-ups, and GST tax liabilities inside simple balance = balance + amount columns, subtle bugs eventually creep in: deleted invoices leave stale totals, refunds corrupt tax reports, and finance teams cannot explain discrepancies during audits. Adopting true double-entry ledger principles solves financial drift permanently.

1. Core Entities of a Relational Accounting Schema

Every financial movement must record balanced entries inside an ACID database transaction (see SQL ACID Transaction Principles):

  • accounts (Chart of Accounts): Categorized into Assets, Liabilities, Equity, Revenue, and Expenses with unique account codes.
  • journal_entries (Header): Captures transaction date, source entity reference (for example, invoice #1042), description, and creator audit ID.
  • journal_lines (Immutable Postings): Individual debit and credit lines where SUM(debit) == SUM(credit) must always hold true before committing the transaction.
Business Event Debit Account Credit Account
Tax Invoice Issued (₹10,000 + ₹1,800 GST) Accounts Receivable (₹11,800) Software Revenue (₹10,000) + Output GST Payable (₹1,800)
Customer Payment Received via Gateway Bank / Clearing Account (₹11,800) Accounts Receivable (₹11,800)
Credit Note / Partial Refund Sales Returns (Debit) + GST Output Adjustment Accounts Receivable / Bank Refund

2. Mandatory Engineering Rules for Financial Precision

  1. Never use FLOAT or DOUBLE: IEEE-754 floating-point binary rounding introduces silent penny/paise drift. Always store monetary amounts in DECIMAL(15, 2) (or integer minor units like paise/cents).
  2. Append-only reversals instead of DELETE: Once a journal entry is posted, prohibit updates or hard deletes; record a reversing journal entry linked via reverses_entry_id so financial audit history remains intact.
M
Reviewed Technical Guide · Updated 03 Dec 2026

Mayur Kadam

Principal Software Architect · SaaS, Laravel & Distributed Systems

Leads software architecture, multi-tenant database design, and cloud security reviews for B2B web platforms, ERPs, and high-throughput APIs.

Ready to start your project?

Tell us what you need and we will get back to you within one business day.