Templates/Finance

Payroll database schema

Pay periods, payslips with earnings and deduction lines per employee.

6 tables, 5 relationships

Opens as a new diagram you can change. Free.

Tables

employees

  • iduuid not null
  • full_nametext not null
  • tax_codetext not null
  • bank_accounttext not null
  • created_attimestamptz not null

pay_periods

  • iduuid not null
  • starts_ondate not null
  • ends_ondate not null
  • paid_ondate not null
  • created_attimestamptz not null

payslips

  • iduuid not null
  • employee_id> employeesuuid not null
  • period_id> pay_periodsuuid not null
  • grossnumeric(12,2) not null
  • netnumeric(12,2) not null
  • created_attimestamptz not null

payslip_lines

  • iduuid not null
  • payslip_id> payslipsuuid not null
  • kindtext not null
  • descriptiontext not null
  • amountnumeric(12,2) not null
  • created_attimestamptz not null

deduction_types

  • iduuid not null
  • nametext not null
  • pre_taxboolean not null
  • created_attimestamptz not null

employee_deductions

  • iduuid not null
  • employee_id> employeesuuid not null
  • deduction_type_id> deduction_typesuuid not null
  • amountnumeric(12,2) 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 "deduction_types" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "name" TEXT NOT NULL,
  "pre_tax" BOOLEAN DEFAULT false NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "employee_deductions" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "employee_id" UUID NOT NULL,
  "deduction_type_id" UUID NOT NULL,
  "amount" NUMERIC(12,2) NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "employees" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "full_name" TEXT NOT NULL,
  "tax_code" TEXT NOT NULL,
  "bank_account" TEXT NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "pay_periods" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "starts_on" DATE NOT NULL,
  "ends_on" DATE NOT NULL,
  "paid_on" DATE NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "payslip_lines" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "payslip_id" UUID NOT NULL,
  "kind" TEXT NOT NULL,
  "description" TEXT NOT NULL,
  "amount" NUMERIC(12,2) NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "payslips" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "employee_id" UUID NOT NULL,
  "period_id" UUID NOT NULL,
  "gross" NUMERIC(12,2) NOT NULL,
  "net" NUMERIC(12,2) NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

ALTER TABLE "payslips" ADD CONSTRAINT "fk_payslips_employee_id" FOREIGN KEY ("employee_id") REFERENCES "employees" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "payslips" ADD CONSTRAINT "fk_payslips_period_id" FOREIGN KEY ("period_id") REFERENCES "pay_periods" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "payslip_lines" ADD CONSTRAINT "fk_payslip_lines_payslip_id" FOREIGN KEY ("payslip_id") REFERENCES "payslips" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "employee_deductions" ADD CONSTRAINT "fk_employee_deductions_employee_id" FOREIGN KEY ("employee_id") REFERENCES "employees" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "employee_deductions" ADD CONSTRAINT "fk_employee_deductions_deduction_type_id" FOREIGN KEY ("deduction_type_id") REFERENCES "deduction_types" ("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.