We will use one common schema:
Schema Owner: BANKING
Tablespace : TRAIN_DATA_TS
Access : READ ONLY for trainees
user will:
- Query data
- Write joins, subqueries, analytics
- Write PL/SQL on their own schema, not this one
📐 ENTITY DESIGN (CORE BANKING)
BRANCHES
|
CUSTOMERS
|
ACCOUNTS
|
TRANSACTIONS
|
LOANS
|
PAYMENTS
Plus:
- USERS (for login simulation)
- AUDIT_LOG (for triggers practice)
🔹 STEP 1: Create BANKING Schema (DBA / Trainer)
CREATE USER banking
IDENTIFIED BY banking
DEFAULT TABLESPACE train_data_ts
TEMPORARY TABLESPACE temp
QUOTA UNLIMITED ON train_data_ts;
GRANT create session, create table, create sequence TO banking;
🔹 STEP 2: Core Master Tables
1️⃣ BRANCHES
CREATE TABLE banking.branches (
branch_id NUMBER PRIMARY KEY,
branch_name VARCHAR2(100),
city VARCHAR2(50),
state VARCHAR2(50)
);
2️⃣ CUSTOMERS
CREATE TABLE banking.customers (
customer_id NUMBER PRIMARY KEY,
first_name VARCHAR2(50),
last_name VARCHAR2(50),
dob DATE,
mobile_no VARCHAR2(15),
email VARCHAR2(100),
city VARCHAR2(50),
created_date DATE DEFAULT SYSDATE
);
3️⃣ ACCOUNTS
CREATE TABLE banking.accounts (
account_id NUMBER PRIMARY KEY,
customer_id NUMBER REFERENCES banking.customers(customer_id),
branch_id NUMBER REFERENCES banking.branches(branch_id),
account_type VARCHAR2(20),
balance NUMBER(15,2),
status VARCHAR2(20),
opened_date DATE
);
🔹 STEP 3: Transaction Tables (Very Important)
4️⃣ TRANSACTIONS
CREATE TABLE banking.transactions (
txn_id NUMBER PRIMARY KEY,
account_id NUMBER REFERENCES banking.accounts(account_id),
txn_date DATE,
txn_type VARCHAR2(10), -- CREDIT / DEBIT
amount NUMBER(12,2),
description VARCHAR2(200)
);
5️⃣ LOANS
CREATE TABLE banking.loans (
loan_id NUMBER PRIMARY KEY,
customer_id NUMBER REFERENCES banking.customers(customer_id),
loan_type VARCHAR2(30),
loan_amount NUMBER(15,2),
interest_rate NUMBER(5,2),
start_date DATE,
status VARCHAR2(20)
);
6️⃣ PAYMENTS
CREATE TABLE banking.loan_payments (
payment_id NUMBER PRIMARY KEY,
loan_id NUMBER REFERENCES banking.loans(loan_id),
payment_date DATE,
amount_paid NUMBER(12,2),
payment_mode VARCHAR2(20)
);
🔹 STEP 4: Sequences (Production Style)
CREATE SEQUENCE banking.branch_seq START WITH 1;
CREATE SEQUENCE banking.customer_seq START WITH 1001;
CREATE SEQUENCE banking.account_seq START WITH 1000001;
CREATE SEQUENCE banking.txn_seq START WITH 1;
CREATE SEQUENCE banking.loan_seq START WITH 50001;
CREATE SEQUENCE banking.payment_seq START WITH 1;
🔹 STEP 5: Sample Data
INSERT INTO banking.branches VALUES (1, 'Main Branch', 'Mumbai', 'MH');
INSERT INTO banking.branches VALUES (2, 'IT Park Branch', 'Bangalore', 'KA');
INSERT INTO banking.customers VALUES
(1001, 'Rahul', 'Sharma', DATE '1990-05-10', '9999999999', 'rahul@gmail.com', 'Mumbai', SYSDATE);
INSERT INTO banking.accounts VALUES
(1000001, 1001, 1, 'SAVINGS', 50000, 'ACTIVE', SYSDATE);
INSERT INTO banking.transactions VALUES
(1, 1000001, SYSDATE, 'CREDIT', 10000, 'Salary');
COMMIT;
🔹 STEP 6: Grant Access to Trainees (READ ONLY)
GRANT SELECT ON banking.branches TO trainee_role;
GRANT SELECT ON banking.customers TO trainee_role;
GRANT SELECT ON banking.accounts TO trainee_role;
GRANT SELECT ON banking.transactions TO trainee_role;
GRANT SELECT ON banking.loans TO trainee_role;
GRANT SELECT ON banking.loan_payments TO trainee_role;
🔹 STEP 7: Advanced (Optional – PRO LEVEL)
🔐 Audit Table for Trigger Practice
CREATE TABLE banking.audit_log (
log_id NUMBER PRIMARY KEY,
table_name VARCHAR2(30),
action VARCHAR2(10),
action_date DATE,
username VARCHAR2(30)
);
Developer can write triggers in their schema referencing this idea.
🏦 ORACLE SQL PRACTICE QUESTIONS
Schema Used: BANKING
Target: SQL mastery for Developer (Practice + Interview)
🔹 LEVEL 1: BASIC SQL (Warm-Up) – 1️⃣ to 1️⃣2️⃣
- Display all branches available in the bank.
- List all customers with their first name, last name, and city.
- Show customer details who belong to Mumbai city.
- Display all accounts with balance greater than 25,000.
- Show all ACTIVE accounts.
- Display unique account types available in the bank.
- List all transactions done today.
- Show transactions with amount greater than 5,000.
- Display customer IDs who have opened accounts.
- Show total number of customers in the bank.
- Display customer names in uppercase.
- Show current system date and time.
🔹 LEVEL 2: JOINS & RELATIONSHIPS – 1️⃣3️⃣ to 2️⃣2️⃣
- Display customer name along with their account number.
- Display customer name, account type, and balance.
- Show branch name where each account is opened.
- Display all customers who do not have any account.
- Display customers and their total number of accounts.
- Display account number and total transaction amount.
- Display customer name, transaction type, and amount.
- Display branches where at least one account exists.
- Display customers who have done DEBIT transactions.
- Display account details where no transactions exist.
🔹 LEVEL 3: AGGREGATES & GROUP BY – 2️⃣3️⃣ to 3️⃣0️⃣
- Display total balance available in the bank.
- Display branch-wise total account balance.
- Display average balance per account type.
- Display customer-wise total transaction amount.
- Display total number of transactions per account.
- Display branches having total balance greater than 50,000.
- Display account types having more than 1 account.
- Display the maximum transaction amount per account.
🔹 LEVEL 4: SUBQUERIES – 3️⃣1️⃣ to 3️⃣6️⃣
- Display customers who have balance greater than the average balance.
- Display accounts having maximum balance.
- Display customers who have never done any transaction.
- Display accounts where total debit amount is greater than total credit amount.
- Display customers who have taken loans.
- Display customers who have more than one account.
🔹 LEVEL 5: ADVANCED SQL (Analytics / Real-World) – 3️⃣7️⃣ to 4️⃣0️⃣
- Display top 3 accounts based on highest balance.
- Rank customers based on total account balance.
- Display each transaction with running balance per account.
- Display customer name and last transaction date.
🧠 INTERVIEW-FOCUSED CHALLENGE QUESTIONS
- Find customers whose first transaction was a DEBIT.
- Find accounts that became zero balance after transactions.
- Detect possible fraud: transactions above average transaction amount of that account.
- Display customers with inactive accounts but active loans.
- Identify branches with no customers from Mumbai.
