0% completed
A Bank Management System (BMS) is a critical application used by banks to handle various services, such as managing customer accounts, processing transactions, managing loans, and overseeing employees. An effective database design ensures smooth operations, secure data handling, and efficient query execution.
In this case study, we’ll explore how to model a database for a Bank Management System (BMS) using Entity-Relationship (ER) diagrams and then map it to a relational database schema. By following this guide, you’ll gain the skills to design and implement a database for any banking system.
Understanding the system's requirements is the first and most crucial step. It ensures that the database will support all necessary functionalities.
For our case study, let's outline the key functionalities that the HMS should support:
We will build the ER diagram for the Hospital Management System through the following four steps.
Entities represent objects or concepts in the system that have data stored about them.
We'll define attributes for each entity, including primary keys (PK) and foreign keys (FK).
Let’s define the relationships between entities in the system.
1. Customer and Account
2. Account and Transaction
3. Account and Loan
4. Loan and Loan_Repayment
5. Customer and Card
6. Account and Card
7. Branch and Account
8. Branch and Employee
Here is the final ER diagram.
When converting the ER diagram into a relational schema for our Bank Management System, we need to carefully handle various components to ensure data integrity and optimal performance. Here are the key considerations:
Entity Tables and Attributes:
Phone_Number
.Foreign Keys and Relationships:
Handling Many-to-Many Relationships:
Here is the Relational Schema diagram.
Now, let's translate the ER model into SQL tables.
CREATE TABLE Customer ( Customer_ID INT PRIMARY KEY, Full_Name VARCHAR(100), City VARCHAR(50), State VARCHAR(50), Area VARCHAR(50), Phone_Number VARCHAR(15), Email VARCHAR(50), Date_of_Birth DATE, Identification_Type VARCHAR(20), -- e.g., Passport, ID Card Identification_Number VARCHAR(50) );
CREATE TABLE Account ( Account_ID INT PRIMARY KEY, Account_Type VARCHAR(20), -- e.g., Savings, Current Balance DECIMAL(10, 2), Date_Opened DATE, Branch_ID INT, Customer_ID INT, FOREIGN KEY (Branch_ID) REFERENCES Branch(Branch_ID), FOREIGN KEY (Customer_ID) REFERENCES Customer(Customer_ID) );
CREATE TABLE Transaction ( Transaction_ID INT PRIMARY KEY, Transaction_Type VARCHAR(20), -- e.g., Deposit, Withdrawal Amount DECIMAL(10, 2), Transaction_Date DATE, Notes TEXT, Account_ID INT, FOREIGN KEY (Account_ID) REFERENCES Account(Account_ID) );
CREATE TABLE Loan ( Loan_ID INT PRIMARY KEY, Loan_Type VARCHAR(20), -- e.g., Home, Personal Loan_Amount DECIMAL(10, 2), Interest_Rate DECIMAL(5, 2), Start_Date DATE, End_Date DATE, Account_ID INT, FOREIGN KEY (Account_ID) REFERENCES Account(Account_ID) );
CREATE TABLE Loan_Repayment ( Repayment_ID INT PRIMARY KEY, Repayment_Date DATE, Amount DECIMAL(10, 2), Loan_ID INT, FOREIGN KEY (Loan_ID) REFERENCES Loan(Loan_ID) );
CREATE TABLE Branch ( Branch_ID INT PRIMARY KEY, Branch_Name VARCHAR(50), Address VARCHAR(100), Phone_Number VARCHAR(15) );
CREATE TABLE Branch_Phone_Number ( Branch_ID INT, Phone_Number VARCHAR(15), PRIMARY KEY (Branch_ID, Phone_Number), FOREIGN KEY (Branch_ID) REFERENCES Branch(Branch_ID) );
CREATE TABLE Employee ( Employee_ID INT PRIMARY KEY, Name VARCHAR(100), Role VARCHAR(50), Email VARCHAR(50), Branch_ID INT, FOREIGN KEY (Branch_ID) REFERENCES Branch(Branch_ID) );
CREATE TABLE Card ( Card_ID INT PRIMARY KEY, Card_Type VARCHAR(20), -- e.g., Credit, Debit Expiry_Date DATE, Card_Limit DECIMAL(10, 2), Customer_ID INT, FOREIGN KEY (Customer_ID) REFERENCES Customer(Customer_ID) );
CREATE TABLE Account_Card ( Account_ID INT, Card_ID INT, PRIMARY KEY (Account_ID, Card_ID), FOREIGN KEY (Account_ID) REFERENCES Account(Account_ID), FOREIGN KEY (Card_ID) REFERENCES Card(Card_ID) );
.....
.....
.....