0% found this document useful (0 votes)
29 views21 pages

Mayilov Semender Database

The document outlines a course work project on a Bank Database System, detailing its structure, including an ER diagram, table creation, SQL queries, and various operations such as data retrieval and management. It emphasizes the transition from manual banking processes to automated systems to enhance efficiency and accuracy. The conclusion highlights the importance of online banking in streamlining operations and improving user experience.

Uploaded by

burzuyevrcb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views21 pages

Mayilov Semender Database

The document outlines a course work project on a Bank Database System, detailing its structure, including an ER diagram, table creation, SQL queries, and various operations such as data retrieval and management. It emphasizes the transition from manual banking processes to automated systems to enhance efficiency and accuracy. The conclusion highlights the importance of online banking in streamlining operations and improving user experience.

Uploaded by

burzuyevrcb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Azerbaijan State Oil and Industry University

Faculty: Information Technology and Management


Department: Computer Engineering
Group: 692.23E
Specialty: Information Security
Subject: Database Systems
Topic: Bank Database System

COURSE WORK

Student: Mayılov Samandar


Instructor: Ibrahimova Ellada
Department Director: Rahimova N.A
BAKI – 2024

Contents

Chapter 1. Bank Database

1.1 Introduction………………………………………..…............….......

1.2 ER diagram……………………………………………..…................

Chapter 2. Creating tables in the bank database

2.1 List of the tables…………………………………..….......................

2.2 Alter, drop columns……………………………..…..........................

2.3 SQL constraints…………….......………………..…..........................

Chapter 3. SQL queries. Using SQL to Retrieve Information from tables.

3.1 SQL select, order by, where command, update, delete statements......

3.2 The in, between, like, and, or, top operators…………........................

3.3 Aggregate functions………….......………………..…........................

3.4 Joining tables………….......………………..…...................................

3.5 SQL Subqueries………….......………………..…...............................

3.6 SQL Views………….......………………..….......................................

Conclusion………….......………………..….......................................…………..

Bank database
1.1 Introduction
The current banking system operates at a slower pace as most tasks are performed
manually, which cannot match the efficiency of computer-based processes. The
system's complexity grows significantly with an increasing number of customers,
leading to a rise in transactions. Logging all these activities manually for future
reference is cumbersome and outdated. Such drawbacks are substantial enough to
impact the overall functionality of the banking system. By adopting digital
solutions, banks can not only meet their operational goals but also gain advantages,
such as reducing the need for manual calculations.

The primary aim of designing a Bank Management System database is to provide a


secure and efficient way to store and manage information related to customers,
employees, accounts, bank cards, branches, departments, and more.

1.2 ER Diagram
The ER (Entity-Relationship) diagram illustrates the structure of the Bank
Management System. It visually represents the database tables and the
relationships among entities like branches, employees, customers, and accounts.
This diagram is essential for organizing structured data and defining the
connections between various functional components of the system. The key
features of the Bank Management System Database Design include managing
customer, employee, branch, account, and bank card information effectively.
Creating tables in the bank database

Tables are utilized to store data within a database. To create a basic table, you must
specify the table's name, define its columns, and determine the data type for each
column. The SQL CREATE TABLE statement is used to define and create a new
table. To add new rows of data into an existing table, the INSERT INTO statement
in SQL Server is used.

2.1 List of tables:

CREATE TABLE Employee (

Id INT PRIMARY KEY IDENTITY,

BranchId INT FOREIGN KEY REFERENCES Branch(Id),

DepartmentId INT FOREIGN KEY REFERENCES Department(Id),

Name NVARCHAR(30) NOT NULL,

Surname NVARCHAR(30) NOT NULL,

BirthDate DATE,

Email NVARCHAR(50) UNIQUE,

PhoneNumber NVARCHAR(30) UNIQUE,

Salary DECIMAL(6,2),

HireDate DATE

);

INSERT INTO Employee (BranchId, DepartmentId, Name, Surname, BirthDate,


Email, PhoneNumber, Salary, HireDate)

VALUES

(1, 1, 'Elvin', 'Mammadov', '1990-05-14', '[email protected]', '0501234567',


3000.00, '2018-06-23'),
(2, 2, 'Leyla', 'Alieva', '1985-03-10', '[email protected]', '0502345678', 3500.00,
'2017-01-15'),

(3, 3, 'Ramil', 'Huseynov', '1992-11-22', '[email protected]', '0503456789',


4000.00, '2019-04-12'),

(4, 4, 'Nigar', 'Mammadova', '1995-07-30', '[email protected]', '0504567890',


2500.00, '2020-09-05');

SELECT * FROM Employee;

Explanation of the code:

1. Table Creation:
o The Employee table is created with columns such as Id, BranchId,
DepartmentId, Name, Surname, BirthDate, Email, PhoneNumber,
Salary, and HireDate.
o BranchId and DepartmentId are foreign keys referencing the Branch
and Department tables respectively.
2. Inserting Data:
o Four rows of data are inserted into the Employee table with
Azerbaijani names and other details such as birthdate, email, phone
number, salary, and hire date.
3. Selecting Data:
o The SELECT * FROM Employee; query fetches all the records from
the Employee table.
2.2 Alter, drop columns

ALTER TABLE Employee

ADD Gender NVARCHAR(15);

ALTER TABLE Employee

DROP COLUMN Gender;

Explanation of Changes:

1. Gender Column Size:


o The size of the Gender column has been changed from
NVARCHAR(20) to NVARCHAR(15). This size is more suitable for
storing gender values like "Male," "Female," or "Other."

2.3 SQL constraints

1) Employee Table

CREATE TABLE Employee (


Id INT PRIMARY KEY IDENTITY,
BranchId INT FOREIGN KEY REFERENCES Branch(Id),
DepartmentId INT FOREIGN KEY REFERENCES Department(Id),
Name NVARCHAR(50) NOT NULL,
Surname NVARCHAR(50) NOT NULL,
BirthDate DATE,
Email NVARCHAR(100) UNIQUE,
PhoneNumber NVARCHAR(50) UNIQUE,
Salary DECIMAL(10, 2) NOT NULL,
HireDate DATE
);

2) Department Table
CREATE TABLE Department (
Id INT PRIMARY KEY IDENTITY,
Name NVARCHAR(50) NOT NULL
);

3) Bank Table

CREATE TABLE Bank (


Id INT PRIMARY KEY IDENTITY,
Name NVARCHAR(50) NOT NULL
);

4) Address Table

CREATE TABLE Address (


Id INT PRIMARY KEY IDENTITY,
AddressLine NVARCHAR(200) NOT NULL,
City NVARCHAR(100) NOT NULL,
Country NVARCHAR(100) NOT NULL
);

5) Branch Table

CREATE TABLE Branch (


Id INT PRIMARY KEY IDENTITY,
BankId INT FOREIGN KEY REFERENCES Bank(Id),
AddressId INT FOREIGN KEY REFERENCES Address(Id)
);
6) Customer Table

CREATE TABLE Customer (


Id INT PRIMARY KEY IDENTITY,
Name NVARCHAR(50) NOT NULL,
Surname NVARCHAR(50) NOT NULL,
Email NVARCHAR(100) UNIQUE,
PhoneNumber NVARCHAR(50) UNIQUE,
BirthDate DATE,
RegisterDate DATE,
BranchId INT FOREIGN KEY REFERENCES Branch(Id),
AddressId INT FOREIGN KEY REFERENCES Address(I

);

7) Position Table

CREATE TABLE Position (


Id INT PRIMARY KEY IDENTITY,
Name NVARCHAR(50) NOT NULL
);
8) EmployeePosition Table (Many-to-Many Relationship)

CREATE TABLE EmployeePosition (


Id INT PRIMARY KEY IDENTITY,
EmployeeId INT FOREIGN KEY REFERENCES Employee(Id),
PositionId INT FOREIGN KEY REFERENCES Position(Id)
);

9) AccountType Table

CREATE TABLE AccountType (


Code INT PRIMARY KEY IDENTITY,
Type NVARCHAR(50) NOT NULL
);

10) Account Table

CREATE TABLE Account (


Id INT PRIMARY KEY IDENTITY,
CustomerId INT FOREIGN KEY REFERENCES Customer(Id),
TypeCode INT FOREIGN KEY REFERENCES AccountType(Code),
DateOpened DATE,
Balance DECIMAL(12, 2)
);

11) Card Table

SQL queries. Using SQL to Retrieve Information from tables.

1. Query to obtain the name of the employees and their departments:


SELECT e.Name AS 'Employee', d.Name AS 'Department'
FROM Employee e
JOIN Department d ON e.DepartmentId = d.Id
ORDER BY e.Name ASC;

2. Query to find the name and surname of the customer with the ID number 4

SELECT Name AS 'Customer Name', Surname AS 'Customer Surname'


FROM Customer
WHERE Id = 4;

3. Query to update the CVV value for a specific card:

UPDATE Card
SET CVV = 843
WHERE Number = '5455001240856770';

4. Query to delete a customer with a specific Id:

DELETE FROM Customer


WHERE Id = 10;

The in, between, like, and, or, top operators

1. Query to find the name, surname of customers and city, country


where they live, born between 2001 and 2002:

SELECT c.Name, c.Surname, a.City, a.Country


FROM Customer c, Address a
WHERE c.AddressId = a.Id
AND c.BirthDate BETWEEN '2001-01-01' AND '2002-01-01';

2. Query to find the name, surname of customers and type and balance of
accounts opened on '2021-12-20' or '2021-12-21':

SELECT c.Name, c.Surname, t.Type, a.Balance


FROM Customer c, AccountType t, Account a
WHERE a.CustomerId = c.Id
AND t.Code = a.TypeCode
AND (a.DateOpened = '2021-12-20' OR a.DateOpened = '2021-12-21');
3.Query to obtain the same result as the previous one using the IN operator
instead of OR:

SELECT c.Name, c.Surname, t.Type, a.Balance


FROM Customer c, AccountType t, Account a
WHERE a.CustomerId = c.Id
AND t.Code = a.TypeCode
AND a.DateOpened IN ('2021-12-20', '2021-12-21');

4. Query to find the name, surname, email, date of birth, and department of
employees born in the 1990s:

SELECT e.Name, e.Surname, e.Email, e.BirthDate, d.Name AS 'Department'

FROM Employee e, Department d

WHERE e.DepartmentId = d.Id

AND e.BirthDate LIKE '199%';

5. Query to return the top 50 percent of accounts where TypeCode = 1:


SELECT TOP 50 PERCENT *
FROM Account
WHERE TypeCode = 1;
Aggregate functions

1. Query to count the number of employees in each department:

SELECT COUNT(*) AS 'Number of Employees', d.Name AS 'Department'


FROM Employee e, Department d
WHERE e.DepartmentId = d.Id
GROUP BY d.Name;

2. Query to count the number of unique customers who own at least


one account:

SELECT COUNT(DISTINCT CustomerId) AS 'No. of customers having


at least one account'
FROM Account;

3. Query to find the average salary of the employees:

SELECT AVG(Salary) AS 'Average Salary'


FROM Employee;

4.Query to obtain the highest and lowest salary of the employees:


SELECT MAX(Salary) AS 'Highest Salary',

MIN(Salary) AS 'Lowest Salary'

FROM Employee;

Joining tables

1. INNER JOIN to obtain the name, surname of the employees and their
account type and balance:

SELECT c.Name, c.Surname, t.Type, a.Balance

FROM Customer c

INNER JOIN Account a ON a.CustomerId = c.Id

INNER JOIN AccountType t ON a.TypeCode = t.Code;

2. LEFT JOIN to obtain the name and surname of the customers and the address
of the branch where they were registered:

SELECT c.Name, c.Surname, a.AddressLine

FROM Branch b

LEFT JOIN Address a ON b.AddressId = a.Id


LEFT JOIN Customer c ON c.BranchId = b.Id;

3. RIGHT JOIN to find the name, surname of the employees and the
department, position they are in:

SELECT e.Name, e.Surname, d.Name AS 'Department', p.Name AS


'Position'

FROM Employee e

RIGHT JOIN Department d ON e.DepartmentId = d.Id

RIGHT JOIN EmployeePosition ep ON ep.EmployeeId = e.Id

RIGHT JOIN Position p ON ep.PositionId = p.Id;

4. Query to find the departments with more than one employee:

SELECT COUNT(*) AS 'Number of Employees', d.Name AS


'Department'

FROM Employee e

FULL JOIN Department d ON e.DepartmentId = d.Id

GROUP BY d.Name

HAVING COUNT(*) > 1;


5. Query to obtain the name, surname, department, position of the employee with
a specific name and surname:

SELECT e.Name, e.Surname, d.Name AS 'Department', p.Name AS


'Position'

FROM Employee e

JOIN Department d ON e.DepartmentId = d.Id

JOIN EmployeePosition ep ON ep.EmployeeId = e.Id

JOIN Position p ON ep.PositionId = p.Id

WHERE e.Name = 'Elvin' AND e.Surname = 'Məmmədov';

SQL Subqueries

1. Query to obtain the balance and the date when the account was opened,
associated with the card numbers specified:

SELECT a.Balance, a.DateOpened

FROM Account a

WHERE a.Id IN (

SELECT AccountId
FROM Card

WHERE Number IN ('4916852799784847', '5202775179297066',


'3545716931593120')

);

2. Query to obtain the name, surname, and department of the employees:

SELECT e.Name, e.Surname, d.Name AS 'Department'


FROM Employee e, Department d
WHERE EXISTS (
SELECT *
FROM Employee
WHERE e.DepartmentId = d.Id
);

3. Query to find the name, surname, and salary of the employee who gets the
highest salary:

SELECT e.Name, e.Surname, e.Salary

FROM Employee e

WHERE e.Salary = (SELECT MAX(Salary) FROM Employee);


SQL Views

1. A view is a virtual table based on the result-set of an SQL statement. In the


following statement, I created a view from joining three tables. It contains name,
surname, department and position of the employees.

CREATE VIEW usp_jobdetails AS


SELECT e.Name, e.Surname, d.Name AS 'Department', p.Name AS 'Position'
FROM Employee e
JOIN Department d ON e.DepartmentId = d.Id
JOIN EmployeePosition ep ON ep.EmployeeId = e.Id
JOIN Position p ON ep.PositionId = p.Id;

SELECT * FROM usp_jobdetails;

2. The following view contains the details of the customer accounts.

CREATE VIEW usp_customeraccountdetails AS


SELECT c.Id, c.Name, c.Surname, t.Type, a.Balance
FROM Customer c
INNER JOIN Account a ON a.CustomerId = c.Id
INNER JOIN AccountType t ON a.TypeCode = t.Code;

SELECT * FROM usp_customeraccountdetails;

CONCLUSION

The Bank Management System (BMS) is a crucial component for


largeenterprises, especially in the banking sector, where handling vast
amounts of data is essential. Traditionally, banking systems were manual,
requiring a lot of time and effort for operations. However, with the advent of
online banking, these systems have been fully virtualized, automating the
process and eliminating manual tasks. In an online banking system,
transactions are processed instantly and can be accessed from anywhere,
providing convenience and speed. Additionally, users can easily manage their
accounts, change branch locations, and perform transactions without the need
for physical presence at a bank. This automated system not only saves time
but also increases accuracy, ensuring that banking operations are more
efficient and reliable compared to traditional manual systems.

You might also like