Templates/Finance

Banking core database schema

Customers, accounts, cards, transactions and transfers between accounts.

5 tables, 5 relationships

Opens as a new diagram you can change. Free.

Tables

customers

  • iduuid not null
  • full_nametext not null
  • emailtext not null
  • kyc_verified_attimestamptz
  • created_attimestamptz not null

bank_accounts

  • iduuid not null
  • customer_id> customersuuid not null
  • numbertext not null
  • currencytext not null
  • balancenumeric(14,2) not null
  • created_attimestamptz not null

cards

  • iduuid not null
  • account_id> bank_accountsuuid not null
  • last4text not null
  • expires_ondate not null
  • frozenboolean not null
  • created_attimestamptz not null

transactions

  • iduuid not null
  • account_id> bank_accountsuuid not null
  • amountnumeric(14,2) not null
  • descriptiontext not null
  • booked_attimestamptz not null
  • created_attimestamptz not null

transfers

  • iduuid not null
  • from_account_id> bank_accountsuuid not null
  • to_account_id> bank_accountsuuid not null
  • amountnumeric(14,2) not null
  • referencetext
  • statustext not null
  • created_attimestamptz not null

As PostgreSQL

The same diagram exports to MySQL, MariaDB, SQLite, SQL Server and Oracle, and to Prisma, Drizzle, SQLAlchemy and Convex models.

CREATE TABLE "bank_accounts" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "customer_id" UUID NOT NULL,
  "number" TEXT NOT NULL UNIQUE,
  "currency" TEXT DEFAULT 'gbp' NOT NULL,
  "balance" NUMERIC(14,2) DEFAULT 0 NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "cards" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "account_id" UUID NOT NULL,
  "last4" TEXT NOT NULL,
  "expires_on" DATE NOT NULL,
  "frozen" BOOLEAN DEFAULT false NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "customers" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "full_name" TEXT NOT NULL,
  "email" TEXT NOT NULL UNIQUE,
  "kyc_verified_at" TIMESTAMPTZ,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "transactions" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "account_id" UUID NOT NULL,
  "amount" NUMERIC(14,2) NOT NULL,
  "description" TEXT NOT NULL,
  "booked_at" TIMESTAMPTZ NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "transfers" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "from_account_id" UUID NOT NULL,
  "to_account_id" UUID NOT NULL,
  "amount" NUMERIC(14,2) NOT NULL,
  "reference" TEXT,
  "status" TEXT DEFAULT 'pending' NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

ALTER TABLE "bank_accounts" ADD CONSTRAINT "fk_bank_accounts_customer_id" FOREIGN KEY ("customer_id") REFERENCES "customers" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "cards" ADD CONSTRAINT "fk_cards_account_id" FOREIGN KEY ("account_id") REFERENCES "bank_accounts" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "transactions" ADD CONSTRAINT "fk_transactions_account_id" FOREIGN KEY ("account_id") REFERENCES "bank_accounts" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "transfers" ADD CONSTRAINT "fk_transfers_from_account_id" FOREIGN KEY ("from_account_id") REFERENCES "bank_accounts" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "transfers" ADD CONSTRAINT "fk_transfers_to_account_id" FOREIGN KEY ("to_account_id") REFERENCES "bank_accounts" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

More Finance templates

Start with one diagram, free

One diagram with two branches, no card needed. Upgrade when your team needs more.