Production Relational SchemaIntermediate → Advanced
Banking
Customers, accounts, transactions, branches and loans.
6 Tables50K+ RecordsTransactionsCTEWindow Functions
Interactive SQL Playground & Query Runner
In-Browser SandboxRun realistic queries against the Banking database. Write custom SQL or solve high-yield interview problems.
Interview Challenge:
easyHigh-Balance Customer Accounts with Branch Details
List all accounts with a balance greater than ₹30,000, along with customer name and city.
INNER JOINFiltering
query.sql
Press Ctrl + Enter to execute
Entity Relationship (ER) & Foreign Key Architecture
Referential integrity mappings and table cardinalities
1:NOwns Accounts
customers
client_id
accounts
client_id
1:NMapped To
accounts
account_id
account_branch
account_id
1:NServices Account
branches
branch_id
account_branch
branch_id
1:NRecords Transactions
accounts
account_id
transactions
account_id
1:NBorrower Of
customers
client_id
loans
client_id
Relational Tables & Column Data Types
Field definitions, types, and primary keys for query construction
customers
3 colsPKclient_id
INTclient_name
VARCHAR(90)city
VARCHAR(60)accounts
5 colsPKaccount_id
INTPKclient_id
INTaccount_type
VARCHAR(30)opened_on
DATEbalance
DECIMAL(12,2)branches
3 colsPKbranch_id
INTbranch_name
VARCHAR(80)city
VARCHAR(60)account_branch
2 colsPKaccount_id
INTPKbranch_id
INTtransactions
5 colsPKentry_id
INTPKaccount_id
INTentry_date
DATEentry_type
VARCHAR(20)amount
DECIMAL(12,2)loans
4 colsPKloan_id
INTPKclient_id
INTprincipal
DECIMAL(12,2)status
VARCHAR(20)Runnable DDL Setup & Seed Script
Run directly in MySQL Workbench, pgAdmin, DBeaver, or terminal
CREATE DATABASE IF NOT EXISTS studyflow_banking;
USE studyflow_banking;
CREATE TABLE customers (
client_id INT PRIMARY KEY,
client_name VARCHAR(90) NOT NULL,
city VARCHAR(60)
);
CREATE TABLE accounts (
account_id INT PRIMARY KEY,
client_id INT,
account_type VARCHAR(30),
opened_on DATE,
balance DECIMAL(12,2),
FOREIGN KEY (client_id) REFERENCES customers(client_id)
);
CREATE TABLE branches (
branch_id INT PRIMARY KEY,
branch_name VARCHAR(80),
city VARCHAR(60)
);
CREATE TABLE account_branch (
account_id INT,
branch_id INT,
PRIMARY KEY (account_id, branch_id),
FOREIGN KEY (account_id) REFERENCES accounts(account_id),
FOREIGN KEY (branch_id) REFERENCES branches(branch_id)
);
CREATE TABLE transactions (
entry_id INT PRIMARY KEY,
account_id INT,
entry_date DATE,
entry_type VARCHAR(20),
amount DECIMAL(12,2),
FOREIGN KEY (account_id) REFERENCES accounts(account_id)
);
CREATE TABLE loans (
loan_id INT PRIMARY KEY,
client_id INT,
principal DECIMAL(12,2),
status VARCHAR(20),
FOREIGN KEY (client_id) REFERENCES customers(client_id)
);
INSERT INTO customers VALUES
(1,'Ira Mehta','Jaipur'),(2,'Dev Nair','Kochi'),(3,'Mira Shah','Surat'),(4,'Kabir Singh','Pune');
INSERT INTO accounts VALUES
(101,1,'Savings','2022-01-10',42000),(102,1,'Current','2023-06-18',85000),
(103,2,'Savings','2024-02-11',27000),(104,3,'Savings','2021-09-04',64000),(105,4,'Savings','2025-01-21',19000);
INSERT INTO branches VALUES
(1,'Central Jaipur','Jaipur'),(2,'Harbor Kochi','Kochi'),(3,'Market Pune','Pune');
INSERT INTO account_branch VALUES
(101,1),(102,1),(103,2),(104,1),(105,3);
INSERT INTO transactions VALUES
(1,101,'2026-01-03','credit',5000),(2,101,'2026-01-08','debit',1200),
(3,101,'2026-02-01','credit',3000),(4,102,'2026-02-05','debit',10000),
(5,103,'2026-02-11','credit',4500),(6,104,'2026-03-02','debit',2500),
(7,104,'2026-03-08','credit',8000),(8,105,'2026-03-12','debit',900);
INSERT INTO loans VALUES
(201,1,120000,'active'),(202,2,75000,'closed'),(203,4,90000,'active');