Comprehensive Database Administrator (DBA) Practical Interview Tasks
This guide provides a detailed walkthrough of all the tasks you might encounter in a DBA interview, particularly for a SELF MICROFINANCE FUND database system. Each section includes SQL examples, explanations, and best practices.

1. Database Creation & Management
Task 1: Create 3 Tables with PK/FK Relationships
Scenario:
Create a microfinance database with tables:
-
Customers (CustomerID, Name, Phone)
-
Loans (LoanID, CustomerID, Amount, IssueDate)
-
Payments (PaymentID, LoanID, Amount, PaymentDate)
SQL Implementation:
-- Create Customers table CREATE TABLE Customers ( CustomerID INT PRIMARY KEY AUTO_INCREMENT, Name VARCHAR(100) NOT NULL, Phone VARCHAR(15) UNIQUE ); -- Create Loans table (1-to-Many with Customers) CREATE TABLE Loans ( LoanID INT PRIMARY KEY AUTO_INCREMENT, CustomerID INT, Amount DECIMAL(10,2) NOT NULL, IssueDate DATE, FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID) ); -- Create Payments table (1-to-Many with Loans) CREATE TABLE Payments ( PaymentID INT PRIMARY KEY AUTO_INCREMENT, LoanID INT, Amount DECIMAL(10,2) NOT NULL, PaymentDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (LoanID) REFERENCES Loans(LoanID) );
Task 2: Insert Sample Data (10+ Records per Table)
-- Insert into Customers INSERT INTO Customers (Name, Phone) VALUES ('John Doe', '255712345678'), ('Jane Smith', '255765432100'), ('Alice Johnson', '255788877766'); -- Insert into Loans INSERT INTO Loans (CustomerID, Amount, IssueDate) VALUES (1, 500000.00, '2023-01-15'), (1, 200000.00, '2023-03-20'), (2, 1000000.00, '2023-02-10'); -- Insert into Payments INSERT INTO Payments (LoanID, Amount) VALUES (1, 100000.00), (1, 150000.00), (2, 50000.00);
Task 3: Modify Tables (Add, Rename, Drop)
-- Add a new column ALTER TABLE Customers ADD COLUMN Email VARCHAR(100); -- Rename a column ALTER TABLE Loans RENAME COLUMN IssueDate TO LoanDate; -- Drop a constraint (remove FK temporarily) ALTER TABLE Payments DROP FOREIGN KEY payments_ibfk_1;
Task 4: Delete & Update Data
-- Delete a customer with no loans DELETE FROM Customers WHERE CustomerID = 3; -- Update a loan amount UPDATE Loans SET Amount = 550000.00 WHERE LoanID = 1;
2. User Management & Security
Task 1: Create a User & Set Password
CREATE USER 'microfinance_admin'@'localhost' IDENTIFIED BY 'SecurePass123!';
Task 2: Grant Privileges
-- Grant full access to the database GRANT ALL PRIVILEGES ON microfinance_db.* TO 'microfinance_admin'@'localhost'; -- Grant read-only access to a specific table GRANT SELECT ON microfinance_db.Customers TO 'reports_user'@'localhost';
3. Backup & Recovery
Task 1: Create Different Backup Types
Full Backup (MySQL)
mysqldump -u root -p microfinance_db > full_backup.sql
Incremental Backup (Using Binary Logs)
FLUSH LOGS; -- Rotates binary logs for incremental backup
Scheduled Backup (Cron Job Example)
# Run every 2 minutes (for testing) */2 * * * * mysqldump -u root -p microfinance_db > /backups/microfinance_$(date +\%Y\%m\%d_\%H\%M\%S).sql
Task 2: Restore from Backup
mysql -u root -p microfinance_db < full_backup.sql
4. Advanced Constraints & Data Types
Task: Create a Table with All Constraints
CREATE TABLE Transactions ( TransactionID INT PRIMARY KEY AUTO_INCREMENT, CustomerID INT NOT NULL, Amount DECIMAL(10,2) CHECK (Amount > 0), TransactionDate DATETIME DEFAULT CURRENT_TIMESTAMP, Status ENUM('Pending', 'Completed', 'Failed') DEFAULT 'Pending', FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID) );
5. Data Retrieval (Complex Queries)
Task 1: Joins & Subqueries
-- INNER JOIN (Customers with Loans) SELECT c.Name, l.Amount FROM Customers c INNER JOIN Loans l ON c.CustomerID = l.CustomerID; -- LEFT JOIN (All Customers, including those without loans) SELECT c.Name, COUNT(l.LoanID) AS TotalLoans FROM Customers c LEFT JOIN Loans l ON c.CustomerID = l.CustomerID GROUP BY c.Name; -- Subquery (Customers who haven’t taken loans) SELECT Name FROM Customers WHERE CustomerID NOT IN (SELECT CustomerID FROM Loans);
Task 2: UNION ALL & CASE
-- UNION ALL (Combine Customers & Loans data) SELECT 'Customer' AS Type, Name AS Detail FROM Customers UNION ALL SELECT 'Loan' AS Type, CONCAT('Amount: ', Amount) FROM Loans; -- CASE (Categorize loans) SELECT LoanID, CASE WHEN Amount > 500000 THEN 'Large Loan' ELSE 'Small Loan' END AS LoanType FROM Loans;
6. Database Replication (Master-Slave)
Task: Configure MySQL Replication
Master Server Config (my.cnf
):
[mysqld] server-id = 1 log-bin = mysql-bin binlog-do-db = microfinance_db
Slave Server Config:
CHANGE MASTER TO MASTER_HOST='master_ip', MASTER_USER='repl_user', MASTER_PASSWORD='password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=107; START SLAVE;
7. Triggers
Task: Log All Loan Changes
CREATE TRIGGER log_loan_changes AFTER UPDATE ON Loans FOR EACH ROW INSERT INTO AuditLog (Action, LoanID, OldAmount, NewAmount) VALUES ('Loan Updated', OLD.LoanID, OLD.Amount, NEW.Amount);
8. Stored Procedures & Events
Task 1: Calculate Total Loan Interest
CREATE PROCEDURE CalculateInterest(IN loan_id INT) BEGIN SELECT Amount * 0.1 AS Interest FROM Loans WHERE LoanID = loan_id; END;
Task 2: Schedule Monthly Report
CREATE EVENT monthly_report ON SCHEDULE EVERY 1 MONTH DO CALL GenerateMonthlyReport();
9. Database Normalization (1NF to 4NF)
Task: Normalize a Denormalized Table
Before (Denormalized):
LoanID | CustomerName | LoanAmount | Payment1 | Payment2 |
---|---|---|---|---|
1 | John Doe | 500000 | 100000 | 150000 |
After (3NF):
-
Loans (LoanID, CustomerID, Amount)
-
Payments (PaymentID, LoanID, Amount, Date)
10. Entity-Relationship Diagram (ERD)
Entities:
-
Customers (1) → (N) Loans (1) → (N) Payments
Tool: MySQL Workbench / Lucidchart
11. Database Views
Task: Create a Customer Loan Summary
CREATE VIEW CustomerLoanSummary AS SELECT c.Name, SUM(l.Amount) AS TotalLoans FROM Customers c LEFT JOIN Loans l ON c.CustomerID = l.CustomerID GROUP BY c.Name;
12. Data Partitioning
Task: Partition by Year
ALTER TABLE Payments PARTITION BY RANGE (YEAR(PaymentDate)) ( PARTITION p2023 VALUES LESS THAN (2024), PARTITION p2024 VALUES LESS THAN (2025) );
13. Database Clustering
Task: Set Up MySQL NDB Cluster
[ndbd] HostName=node1 [ndbd] HostName=node2 [mysqld] HostName=sql_node
14. API Integration
Task: Fetch Loans via REST API (Node.js)
const express = require('express'); const mysql = require('mysql'); const app = express(); const db = mysql.createConnection({ host: 'localhost', user: 'root', password: '', database: 'microfinance_db' }); app.get('/api/loans', (req, res) => { db.query('SELECT * FROM Loans', (err, results) => { if (err) throw err; res.json(results); }); }); app.listen(3000, () => console.log('API running on port 3000'));
Final Notes
✅ Covers all interview tasks (SQL, Backups, Replication, API).
✅ Real-world microfinance examples.
✅ Optimized for MySQL but adaptable to other DBs.