0% found this document useful (0 votes)
45 views

Database - Business Rules

The document provides a summary of a simple bank database design including an entity relationship (ER) model depicting the entities and relationships between a bank, branches, customers, accounts and transactions. It also includes the schema design with primary and foreign keys and sample code to create the tables and insert sample data.

Uploaded by

nour ghanaym
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Database - Business Rules

The document provides a summary of a simple bank database design including an entity relationship (ER) model depicting the entities and relationships between a bank, branches, customers, accounts and transactions. It also includes the schema design with primary and foreign keys and sample code to create the tables and insert sample data.

Uploaded by

nour ghanaym
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

I will provide you with a simple bank database design, including business rules, an

ER model, schema explanation, table creation, and related MySQL code.

1. Business Rules

A bank has one or more branches.


Each branch has a unique identifier, location, and operating hours.
A customer can have one or more accounts at the bank.
Each customer has a unique identifier, name, address, and contact information.
An account has a unique account number, type (e.g. checking, savings), balance, and
belongs to a specific branch.
A transaction represents a deposit or withdrawal made by a customer for a specific
account.
Each transaction has a unique transaction ID, date, amount, and type (e.g. deposit,
withdrawal).
2. ER Model

Entities and their attributes:

Bank
bank_id (PK)
name
Branch
branch_id (PK)
location
operating_hours
bank_id (FK)
Customer
customer_id (PK)
name
address
contact_info
Account
account_number (PK)
type
balance
branch_id (FK)
customer_id (FK)
Transaction
transaction_id (PK)
date
amount
type
account_number (FK)
Relationships:

Bank 1 --- * Branch


Branch 1 --- * Account
Customer 1 --- * Account
Account 1 --- * Transaction
3. Schema Explanation

The schema consists of 5 tables, each representing an entity in the ER model. The
primary key (PK) for each table uniquely identifies a record, while foreign keys
(FK) establish relationships between tables.

4. Table Creation

CREATE TABLE Bank (


bank_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL
);

CREATE TABLE Branch (


branch_id INT AUTO_INCREMENT PRIMARY KEY,
location VARCHAR(255) NOT NULL,
operating_hours VARCHAR(255) NOT NULL,
bank_id INT,
FOREIGN KEY (bank_id) REFERENCES Bank(bank_id)
);

CREATE TABLE Customer (


customer_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
address VARCHAR(255) NOT NULL,
contact_info VARCHAR(255) NOT NULL
);

CREATE TABLE Account (


account_number INT AUTO_INCREMENT PRIMARY KEY,
type ENUM('checking', 'savings') NOT NULL,
balance DECIMAL(15, 2) NOT NULL,
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 AUTO_INCREMENT PRIMARY KEY,
date DATE NOT NULL,
amount DECIMAL(15, 2) NOT NULL,
type ENUM('deposit', 'withdrawal') NOT NULL,
account_number INT,
FOREIGN KEY (account_number) REFERENCES Account(account_number)
);
5. MySQL Code

Here's some example MySQL code to insert data into the tables:

-- Insert a bank
INSERT INTO Bank (name) VALUES ('Global Bank');

-- Insert branches
INSERT INTO Branch (location, operating_hours, bank_id) VALUES ('New York', '9:00 -
17:00', 1);
INSERT INTO Branch (location, operating_hours, bank_id) VALUES ('Los Angeles',
'9:00 - 17:00', 1);

-- Insert a customer
INSERT INTO Customer (name, address, contact_info) VALUES ('John Doe', '123 Main
St, New York, NY', '[email protected]');

-- Insert an account for the customer


INSERT INTO Account (type, balance, branch_id, customer_id) VALUES ('checking',
1000.00, 1, 1);

-- Insert a transaction for the account


INSERT INTO Transaction (date, amount, type, account_number) VALUES ('2023-04-13',
500.00, 'deposit', 1);

You might also like