bank database (1)

73
Frostburg State University Bank Database Project By Rushikesh Parekh

Upload: rushikesh-parekh

Post on 14-Aug-2015

144 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Bank Database (1)
Page 2: Bank Database (1)

Table of Contents Page Number

Chapter 1…………………………………………………………………………………2

Chapter 2…………………………………………………………………………………5

Chapter 3…………………………………………………………………………………6

Chapter 4…………………………………………………………………………………10

Chapter 5…………………………………………………………………………………14

Chapter 6…………………………………………………………………………………25

Chapter 7…………………………………………………………………………………33

Chapter 8…………………………………………………………………………………40

Chapter 9 ………………………………………………………………………………...47

Chapter 10………………………………………………………………………………..53

Chapter 11………………………………………………………………………………..58

Chapter 12………………………………………………………………………………..60

Chapter 13………………………………………………………………………………..63

1

Page 3: Bank Database (1)

Chapter 1- Description and assumptions

The purpose of this document its underline all the important functions of this database

that is being created for Frostburg State University bank. This database will hold all the records

associated with the bank. The database will have branch information that lists the name, address,

departments etc. In the requirements there is a branch entity which has characteristics such as

Branch ID, Branch Name, number of employees in a branch, manager name and other

characteristics that will be shown later in this document . One of the problems that we run into is

that the requirements have transitive dependencies, partial dependencies or a row has multiple

values. For example in the Branch entity the Branch ID determines the Branch Name and the

Branch name determines number of employees that each branch has. To make sure that the tables

are normalized Branch ID, Branch name and other associated characteristics are designated a

table and the Branch departments will be given another table because they have multiple values.

This will ensure minimal use of memory and neat tables. The same type of normalization will be

done for the Employees and Customers entities.

    This project will utilize Oracle Database for the implementation of the Frostburg State

University Bank Database. The project will start at 4/28/2015 and it is projected to be finished by

5/14/2015. The major milestones of this project will be to normalize the required entities. Once

the entities and relationships have been figured out the next step will be to create the tables and

add data to those tables, this part of the process will be the most time consuming. The final part

will be the testing part of the project. This is where the database will be tested against many

simple and complex queries. This part of the process is important because this will ensure many

different ways in which the Bank data will be represented. Also this is where some of the

2

Page 4: Bank Database (1)

requirements of this project will be met, mainly the aspects of the project that require

calculations.

    The cost of creating this database is estimated to be around 45,000$. The price is high

because of many reasons. First of all the licensing of the software itself is half the cost. The

creation of this database will increase the profit of this bank because of the efficiency of the

system. No more does the bank have to invest in paper to keep records of their clients and

employees; this causes the bank to have decreased expenses. The employees will be more

productive and have higher job satisfaction because they are dealing with and advanced piece of

technology which can be utilized easily, it can be accessed by all employees at the same time and

employees can easily search through the record to find what they are looking for. This piece of

technology also makes the bank more competitive because the efficiency and the effectiveness of

the Oracle Database will ensure fast and smooth business transactions, which in turn attract more

customers to the bank.  Also using the Oracle Database ensures higher security of the bank

records. In case of a fire at the bank the heart of the operation, which are the bank records, will

be in a safe location away from the branches of the Bank. If there is a fire at any given branch

location none of the data will be lost. Also the bank will not be liable for any loss of information

or a breach of any information that would be caused by a hacker. This practice safeguards the

company hosting the bank information will always have to be up to date with their security

measures. Hosting the bank database on a server takes away a huge burden of making sure the

system is secure, over time the bank might have to upgrade the system which down the road

would be very expensive for the bank. The only upgrade the bank might need would be to

upgrade their computer hardware. They will not have to worry about the software aspect because

their licensee will do that on their end. If the bank wants their own software to be created they

3

Page 5: Bank Database (1)

would have to hire third party developers to create and maintain the software, which would cost

the bank five times more than the price listed above.

Also the software requirements for the database guarantees that the bank need not worry

about spending huge sums of money on high quality personal computers for their branches. The

system requirements for desktops are as follows. The recommended operating system is

Windows Vista and above, 300 GB or higher of Hard Drive memory, RAM capacity of 3 GB or

above. The recommended processers that can be utilized are Intel I3 or an I3 equivalent or

stronger processor. The minimum requirements listed above should be sufficient to run the

Oracle application, if and only if the computers run that particular application only.

The final product will consist of the following tables, Branch Table, Employee Table,

Customers Table, Accounts Table, Loans Table, and Account/Loan Transactions Table. There

are three other tables but ones listed above contain the main data, the tables not mentioned here

only contain redundant data that connect the tables listed above. The three tables not listed are

listed in Chapter six of this documentation. The Branch, Employees, Accounts, Loans, and

Customers table will contain concrete data related to distinct branches, distinct employees and

distinct customers including the account customers open and the loans they take out, calculations

like number of employees per branch are listed queries since they are not concrete data and need

to be calculated. The account transactions table will contain all the data pertaining the all the

transaction made with the bank by the customers. They will include information on loan, credit

card, deposit or withdrawal transactions. The transactions will be distinct to the accounts they are

related to and the accounts are related to distinct customers. Customers can have more than one

account associated with them.

4

Page 6: Bank Database (1)

Chapter 2

5

Page 7: Bank Database (1)

Chapter 3

·Branch {

Branch_ID ,

Branch_Name,

Branch Address,

Branch_Phone_Number,

Driving Teller,

Manager Name,

Branch URL,

}

·Branch_Department_ List {

Branch ID,

Departments

}

·Employees{

SSN,

Employee_ID

Name,

Branch_Location,

Home_Address,

Home_Phone_Number,

Sex,

Race,

Date_OF_Birth,

6

Page 8: Bank Database (1)

Hire_Date,

Title,

Yearly Salary

Phone_Extension,

Highest_Degree,

Graduation_Date

}

·Customers {

SSN ,

Customer ID,

Name,

Address,

Home_Phone,

Work_Phone,

Bank_Card_NO,

}

·Accounts {

Account ID ,

EMP_ID,

Branch_ID,

Data_Opened,

Type,

Initial_Deposit,

Web_Id,

7

Page 9: Bank Database (1)

Web_Password

}

·Loans{

Loan_ID

Amount,

Type,

Duration_Of_Loan

Date_Issued,

Minimum Payment/Month

}

· Account Transaction {

Account Id,

Transaction ID

Type,

Date and Time,

Description,

Amount,

Location_of_Transaction,

Branch_ID,

Tellers ID,

}

· Loan Transaction(

Loan ID,

8

Page 10: Bank Database (1)

Date,

Branch_ID,

)

9

Page 11: Bank Database (1)

Chapter 4

PK = Primary Key and FK = Foreign Key

·Branch {

Branch_ID (PK/FK) ,

Branch_Name,

Branch Address,

Branch_Phone_Number,

Driving Teller,

Manager Name,

Branch URL

}

·Branch_Department_ List {

Branch ID (PK/FK),

Departments

}

·Employees{

SSN (PK),

Employee_ID (FK)

Name,

Branch_Location,

Home_Address,

Home_Phone_Number,

Sex,

Race,

10

Page 12: Bank Database (1)

Date_OF_Birth,

Title,

Yearly Salary

Phone_Extension,

Highest_Degree,

Graduation_Date

}

Employ_works_for_branch

{

Employee_ID,

Branch_ID

}

·Customers {

SSN (PK) ,

Customer ID (FK),

Name,

Address,

Home_Phone,

Work_Phone,

Bank_Card_NO,

}

·Accounts {

Account ID (PK/FK) ,

EMP_ID (FK),

11

Page 13: Bank Database (1)

Branch_ID (FK),

Data_Opened,

Type,

Initial_Deposit,

Web_Id,

Web_Password

}

·Loans{

Loan_ID (PK/FK)

Amount,

Type,

Duration_Of_Loan

Date_Issued,

Minimum Payment/Month

}

· Account Transaction {

Account Id (PK/ FK),

Transaction ID

Type,

Date and Time,

Description,

Amount,

Location_of_Transaction,

12

Page 14: Bank Database (1)

Branch_ID,

Tellers ID,

}

· Loan Transaction(

Loan ID(PK/FK),

Date,

Type,

Branch_ID (FK),

)

13

Page 15: Bank Database (1)

Chapter 5

First Normal Form

All of the tables are in First Normal form since they do not have any multiple values in the tables.

·Branch {

Branch_ID (PK/FK) ,

Branch_Name,

Branch Address,

Branch_Phone_Number,

Driving Teller,

Manager Name,

Branch URL

}

·Branch_Department_ List {

Branch ID (PK/FK),

Departments

}

·Employees{

SSN (PK),

Employee_ID (FK)

Name,

Home_Address,

Home_Phone_Number,

Sex,

Race,

14

Page 16: Bank Database (1)

Date_OF_Birth,

Title,

Yearly Salary

Phone_Extension,

Highest_Degree,

Graduation_Date

}

Employ_works_for_branch

{

Employee_ID,

Branch_ID

}

·Customers {

SSN (PK) ,

Customer ID (FK),

Name,

Address,

Home_Phone,

Work_Phone,

Bank_Card_NO,

}

·Accounts {

Account ID (PK/FK) ,

EMP_ID (FK),

15

Page 17: Bank Database (1)

Branch_ID (FK),

Data_Opened,

Type,

Initial_Deposit,

Web_Id,

Web_Password

}

·Loans{

Loan_ID (PK/FK)

Amount,

Type,

Duration_Of_Loan

Date_Issued,

Minimum Payment/Month

}

· Account Transaction {

Account Id (PK/ FK),

Transaction ID

Type,

Date and Time,

Description,

Amount,

Location_of_Transaction,

16

Page 18: Bank Database (1)

Branch_ID,

Tellers ID,

}

· Loan Transaction(

Loan ID(PK/FK),

Date,

Type,

Branch_ID (FK),

)

Second Normal form

·Branch {

Branch_ID (PK/FK) ,

Branch_Name,

Branch_Phone_Number,

Driving Teller,

Manager Name,

Branch URL

}

·Branch_Department_ List {

Branch ID (PK/FK),

Departments

}

·Employees{

17

Page 19: Bank Database (1)

SSN (PK),

Employee_ID (FK)

Name,

Home_Address,

Home_Phone_Number,

Sex,

Race,

Date_OF_Birth,

Title,

Yearly Salary

Phone_Extension,

Highest_Degree,

Graduation_Date

}

Since Branch Location is functionally dependent on Employee id we create another table to satisfy the Second normal form.

Employ_works_for_branch

{

Employee_ID,

Branch_ID,

Branch_Address

}

·Customers {

SSN (PK) ,

Customer ID (FK),

18

Page 20: Bank Database (1)

Name,

Address,

Home_Phone,

Work_Phone,

Bank_Card_NO,

}

·Accounts {

Account ID (PK/FK) ,

EMP_ID (FK),

Branch_ID (FK),

Data_Opened,

Type,

Initial_Deposit,

Web_Id,

Web_Password

}

·Loans{

Loan_ID (PK/FK)

Amount,

Type,

Duration_Of_Loan

Date_Issued,

Minimum Payment/Month

19

Page 21: Bank Database (1)

}

· Account Transaction {

Account Id (PK/ FK),

Transaction ID

Type,

Date and Time,

Description,

Amount,

Location_of_Transaction,

Branch_ID,

Tellers ID,

}

· Loan Transaction(

Loan ID(PK/FK),

Date,

Type,

Branch_ID (FK),

)

Third Normal Form

Since there are no transitive dependencies the tables are in third normal form.

·Branch {

Branch_ID (PK/FK) ,

Branch_Name,

20

Page 22: Bank Database (1)

Branch_Address,

Branch_Phone_Number,

Driving Teller,

Manager Name,

Branch URL

}

·Branch_Department_ List {

Branch ID (PK/FK),

Departments

}

·Employees{

SSN (PK),

Employee_ID (FK)

Name,

Home_Address,

Home_Phone_Number,

Sex,

Race,

Date_OF_Birth,

Title,

Hire_Date,

Yearly Salary

Phone_Extension,

Highest_Degree,

21

Page 23: Bank Database (1)

Graduation_Date

}

Employ_works_for_branch

{

Employee_ID,

Branch_ID,

}

·Customers {

SSN (PK) ,

Customer ID (FK),

Name,

Address,

Home_Phone,

Work_Phone,

Bank_Card_NO,

}

·Accounts {

Account ID (PK/FK) ,

EMP_ID (FK),

Branch_ID (FK),

Data_Opened,

Type,

Initial_Deposit,

22

Page 24: Bank Database (1)

Web_Id,

Web_Password

}

·Loans{

Loan_ID (PK/FK)

Amount,

Type,

Duration_Of_Loan

Date_Issued,

Minimum Payment/Month

}

· Account Transaction {

Account Id (PK/ FK),

Transaction ID

Type,

Date and Time,

Description,

Amount,

Location_of_Transaction,

}

· Loan Transaction(

Loan ID(PK/FK),

Date,

23

Page 25: Bank Database (1)

Type,

Branch_ID (FK),

)

24

Page 26: Bank Database (1)

Chapter 6-Structure and Constraints

Create Table Branch

(

Branch_ID int not null,

Branch_Name varchar(25) not null,

Branch_Address varchar(25) not null,

Branch_Phone_Number int not null ,

Driving_Teller varchar(3) not null,

Manager_Name varchar(20) not null,

Branch_URL varchar(30) not null,

Primary Key(Branch_ID)

25

Page 27: Bank Database (1)

);

Name Null? Type

BRANCH_ID NOT NULL NUMBER(38)

BRANCH_NAME NOT NULL VARCHAR2(25)

BRANCH_PHONE_NUMBER NOT NULL NUMBER(38)

DRIVING_TELLER NOT NULL VARCHAR2(3)

MANAGER_NAME NOT NULL VARCHAR2(20)

BRANCH_URL NOT NULL VARCHAR2(30)

BRANCH_ADDRESS NOT NULL VARCHAR2(35)

Create Table Branch_departments

(

Branch_ID int not null,

Department varchar(10) not null,

Primary_Key(Branch_ID),

constraint fk_Depts Foreign Key (Branch_ID) REFERENCES Branch(Branch_ID)

);

Name Null? Type

BRANCH_ID NOT NULL NUMBER(38)

DEPARTMENT NOT NULL VARCHAR2(10)

create table Employees(

SSN int not null,

Employee_ID int not null,

Name varchar(25) not null,

Home_Address varchar(30) not null,

26

Page 28: Bank Database (1)

Home_Phone_Number int not null,

Sex varchar(4) not null,

Race varchar(10) not null,

Date_OF_Birth Date not null,

Title varchar(10),

Hire_Date date not null,

Yearly_Salary int not null,

Phone_Extension int not null,

Highest_Degree varchar(15) not null,

Graduation_Date date not null,

Primary Key(SSN)

CONSTRAINT emp_ID UNIQUE (Employee_ID)

);

Name Null? Type

SSN NOT NULL NUMBER(38)

EMPLOYEE_ID NOT NULL NUMBER(38)

NAME NOT NULL VARCHAR2(25)

HOME_ADDRESS NOT NULL VARCHAR2(30)

HOME_PHONE_NUMBER NOT NULL NUMBER(38)

SEX NOT NULL VARCHAR2(4)

RACE NOT NULL VARCHAR2(10)

DATE_OF_BIRTH NOT NULL DATE

TITLE VARCHAR2(10)

HIRE_DATE NOT NULL DATE

YEARLY_SALARY NOT NULL NUMBER(38)

PHONE_EXTENSION NOT NULL NUMBER(38)

HIGHEST_DEGREE NOT NULL VARCHAR2(15)

GRADUATION_DATE NOT NULL DATE

27

Page 29: Bank Database (1)

create table Employee_Branch_Location

(

Branch_ID int not null references Branch(Branch_ID),

Employee_ID int not null,

Primary Key (Branch_ID),

constraint fk_Local Foreign Key (Employee_ID) REFERENCES Employees(Employee_ID)

);

Name Null? Type

BRANCH_ID NOT NULL NUMBER(38)

EMPLOYEE_ID NOT NULL NUMBER(38)

create table customers

(

SSN int not null,

Customer_ID int not null,

Name varchar(15) not null,

Address varchar(30) not null,

Home_Phone int not null,

Work_Phone int not null,

Credit_Card_Number int not null,

28

Page 30: Bank Database (1)

Primary Key(SSN),

constraint Cust_ID Unique (customer_ID)

);

Name Null? Type

SSN NOT NULL NUMBER(38)

CUSTOMER_ID NOT NULL NUMBER(38)

NAME NOT NULL VARCHAR2(15)

ADDRESS NOT NULL VARCHAR2(30)

HOME_PHONE NOT NULL NUMBER(38)

WORK_PHONE NOT NULL NUMBER(38)

CREDIT_CARD_NUMBER NOT NULL NUMBER(38)

Create table accounts

(

Account_ID int not null references customers(customer_ID),

EMP_ID int not null references employees(employee_ID),

Branch_ID int not null references branch(Branch_ID),

Date_opened date,

type varchar(20) not null,

initial_deposit int not null,

web_id varchar(15) not null,

web_password varchar(15) not null,

primary key(account_ID)

);

Name Null? Type

ACCOUNT_ID NOT NULL NUMBER(38)

EMP_ID NOT NULL NUMBER(38)

BRANCH_ID NOT NULL NUMBER(38)

DATE_OPENED DATE

TYPE NOT NULL VARCHAR2(20)

29

Page 31: Bank Database (1)

INITIAL_DEPOSIT NOT NULL NUMBER(38)

WEB_ID NOT NULL VARCHAR2(15)

WEB_PASSWORD NOT NULL VARCHAR2(15)

create table Loans

(

Loan_ID int not null,

Amount int not null,

Duration_of_Loan varchar(20) not null,

Date_Issued Date not null,

Minimum_Payment_per_Month int not null,

interest_rate varchar(8) not null,

type varchar(8) not null,

primary Key(Loan_ID)

);

Name Null? Type

LOAN_ID NOT NULL NUMBER(38)

AMOUNT NOT NULL NUMBER(38)

DURATION_OF_LOAN NOT NULL VARCHAR2(20)

DATE_ISSUED NOT NULL DATE

MINIMUM_PAYMENT_PER_MONTH NOT NULL NUMBER(38)

INTEREST_RATE NOT NULL VARCHAR2(8)

TYPE NOT NULL VARCHAR2(8)

30

Page 32: Bank Database (1)

create table account_transaction

(

Account_ID int not null references customers(customer_id),

Transaction_ID int not null,

type varchar(20) not null,

Date_and_Time date not null,

Description varchar(25) not null,

Amount int not null,

Location_of_Transaction int not null references Branch(Branch_ID),

Primary Key(Account_ID)

);

Name Null? Type

ACCOUNT_ID NOT NULL NUMBER(38)

TRANSACTION_ID NOT NULL NUMBER(38)

TYPE NOT NULL VARCHAR2(20)

DATE_AND_TIME NOT NULL DATE

DESCRIPTION NOT NULL VARCHAR2(25)

AMOUNT NOT NULL NUMBER(38)

LOCATION_OF_TRANSACTION NOT NULL NUMBER(38)

create table Customer_Accounts

(

Customer_ID int not null references customers(customer_ID),

Account_ID int not null references accounts(account_ID)

);

Name Null? Type

CUSTOMER_ID NOT NULL NUMBER(38)

ACCOUNT_ID NOT NULL NUMBER(38)

31

Page 33: Bank Database (1)

create table Employee_Branch_Location

(

Branch_ID int not null references Branch(Branch_ID),

Employee_ID int not null,

constraint fk_Local Foreign Key (Employee_ID) REFERENCES Employees(Employee_ID)

);

Name Null? Type

BRANCH_ID NOT NULL NUMBER(38)

EMPLOYEE_ID NOT NULL NUMBER(38)

Create Table Branch_departments

(

Branch_ID int not null references branch(Branch_id),

Department varchar(10) not null,

constraint fk_Depts Foreign Key (Branch_ID) REFERENCES Branch(Branch_ID) );

Name Null? Type

BRANCH_ID NOT NULL NUMBER(38)

DEPARTMENT NOT NULL VARCHAR2(25)

32

Page 34: Bank Database (1)

Chapter 7- Inserting Data

Branch Table

Employee Table

33

Page 35: Bank Database (1)

Employee Table continued…

34

Page 36: Bank Database (1)

Customers Table

35

Page 37: Bank Database (1)

Accounts Table

Loans Table

Account Transaction Table

36

Page 38: Bank Database (1)

Account Transaction Table Continued

37

Page 39: Bank Database (1)

Branch Departments Table

38

Page 40: Bank Database (1)

Employee Branch Location table

Customer ID and Account ID table

39

Page 41: Bank Database (1)

Chapter 8-Simple Queries

40

Page 42: Bank Database (1)

1.) Branch Location Infoselect Branch_ID , UPPER( Branch_Name) , Branch_Address from Branch

2.) Employee Location InfoSelect Title,name,lower(home_address) from employees

3.) Employee years of experience working at a particular Branch.select employee_ID,round( (sysdate-hire_date)/365) from employees

4.) Simple Customer Information in one rowselect SSN || ' , ' || Name || ' , ' || Address || ' , ' || home_phone from customers

41

Page 43: Bank Database (1)

5.) Distinct Bank departmentsselect distinct department from branch_departments

6.) select Employee_ID , Name, yearly_salary from employees where yearly_salary<=80000 or yearly_salary>= 100000This shows employees who have salaries greater than 100000 or less than 80000

7.) select Employee_ID , Name from employees where name between 'A' and 'E'Shows every employee whose name start with any letters between A and E

42

Page 44: Bank Database (1)

8.) select customer_id, Name from customers where name not between 'A' and 'E'Shows every employee whose name doesn’t start with any letters between A and E

9.) select Name from customers where ssn not in (915892269,312557412,414895547)shows names of people who do not have those SSN number

10.) SSN and name of employees with the number 2 as the last digit of their social security number

Select SSN, Name from employees where SSN like ‘%2’

11.)select title , avg(Yearly_salary) from employees group by titleAvg salaries which are group by titles

43

Page 45: Bank Database (1)

12.)select title , max(Yearly_salary) from employees group by titleMax salaries which are group by titles

13.)select account_id ,sum(amount) as "Total deposit" from account_transaction where type='Deposit' group by account_idShows the total deposits done by customers.

14.)select account_id ,sum(amount) as "Total Withdraw" from account_transaction where type='Withdraw' group by account_idShows the total withdraws done by customers

15.) select type, sum(amount) from account_transaction group by typeShows the total amount of transaction done grouped by their type.

16.)select name, max(yearly_salary) as "Income" from employees group by name having max(yearly_salary)>80000Shows the max salary greater than 80000 of every employee

44

Page 46: Bank Database (1)

17.)select name, sum(yearly_salary) as "Income" from employees where title = 'Manager' group by name having max(yearly_salary)>80000 Managers that have high salaries are group by titles.

18.)select account_id, sum(amount) from account_transaction group by account_id having sum(amount)>10The total balance of each account

19.)select transaction_id, sum(amount) from account_transaction group by transaction_id having sum(amount)>2500The total amount of money deposited according to transaction_ID

20.)This shows how many transactions a certain account has made

select count(transaction_id), account_id from account_transaction group by account_id having count(transaction_id)>2

45

Page 47: Bank Database (1)

21.)select * from employees order by yearly_salaryEmployee table ordered by lowest to highest yearly pay

22.)select account_id,amount,type from account_transaction where account_id=300 order by amountaccount transactions table ordered by lowest to highest transactions for account id 300

23.)select loan_id,amount from loans order by amount descOrders the loan amounts by descending order

46

Page 48: Bank Database (1)

24.)Orders Employee Table By Raceselect name,race from employees order by race

25.)Orders Employees by their name in descending orderselect name,ssn from employees order by name desc

47

Page 49: Bank Database (1)

Chapter 9- Queries With Functions

1.) select upper(name), initcap(sex), lower(RAce) from employees

2.) select concat(name, sex) from employees where yearly_salary>60000Concatenation of name and the sex of an individual earning more than 60000 a year

3.) Substring of names, chooses only the first 8 charactersselect substr(Name,1,8) as "Name" from employees where yearly_salary>60000

48

Page 50: Bank Database (1)

4.) select rpad(name,10) as "Name", lpad(home_address,20) as " Home Address" from employees where yearly_salary>60000Good example of padding

5.) select 'The Job Title of ' | | initcap(Name) | | ' is ' | | lower(title) as "Employee Job Details" from employeesShows a nice sentence talking about employee job title

49

Page 51: Bank Database (1)

6.) select 'The Yearly Salary of ' | | initcap(Name) | | ' is ' | | yearly_salary as "Employee Job Salary"

from employeesShows the Yearly salary in a more meaningful way

7.) select account_id,transaction_id,Date_and_time,lower(type) from account_transaction

50

Page 52: Bank Database (1)

Shows the types of transaction in lower case

8.) This query shows character manipulationselect name ||' -------------------->> '|| home_address as "Employee Address" from employees

9.) Selects the name of Customers whose address length is greater than 30select name,address from customers where length(address)>30

10.)Query That shows Employees Ageselect Name, round((sysdate-date_of_birth)/365) as "Employee Age" from employees

51

Page 53: Bank Database (1)

11.)Shows different frequencies of yearly salary grouped by Titlesselect title, avg(yearly_salary),min(yearly_salary),max(yearly_salary),sum(yearly_salary) from employees group by title

12.)Shows new salaries of employees

52

Page 54: Bank Database (1)

13.)Shows how many employees have the same titleselect title, count(name) as " Employees with same Title" from employees group by title

14.)Number of employees in a branchselect Branch_id, count(employee_id) as "Num of Employees in a branch" from employee_branch_location group by Branch_id

15.)Number of account associated with Employeesselect tellers_id , count(account_id) as "account associated with teller" from account_transaction group by tellers_id

53

Page 55: Bank Database (1)

Chapter 10- Joins

1.) This joins branch location, employeeid, customer id and account id to the same tableselect * from Employee_Branch_Location natural join Customer_Accounts

2.) This shows the departments the employees work forselect *from branch_departments natural join Employee_Branch_Location

54

Page 56: Bank Database (1)

3.) Join loan id and account idselect accounts.account_id, loans.Loan_id from accounts inner join loans ON accounts.account_id = loans.loan_id

4.) Shows the interest rate associated with the account select accounts.account_id, loans.interest_rate from accounts inner join loans ON accounts.account_id = loans.loan_id

5.) Basic info on customers account.select accounts.account_id, customers.name,accounts.web_id,accounts.web_Password, customers.address,customers.credit_card_number from accounts inner join customers ON accounts.account_id = Customers.customer_id

6.) This shows customers info and the type of account they have openedselect customers.ssn,customers.name, customers.home_phone, accounts.type from customers inner join accounts on customers.customer_id = accounts.account_id

55

Page 57: Bank Database (1)

7.) This shows the name associated with the transactions select customers.name,customers.customer_id, account_transaction.transaction_id, account_transaction.type , account_transaction.amount from customers inner join account_transaction on customers.customer_id = account_transaction.account_id

8.) This table shows the customer’s name and the type of account they have opened.

56

Page 58: Bank Database (1)

select customers.name,accounts.type from customers full outer join accounts on customers.customer_id = accounts.account_ID order by Customers.name

9.) This table shows the customer’s name their account id, the employee id of their account creator and their transaction information.select customers.name,account_transaction.tellers_id, transaction_id,description from customers full outer join account_transaction on customers.customer_id = account_transaction.account_ID order by account_ID

10.)This Table shows the employees that have created an account for customers.

57

Page 59: Bank Database (1)

select employees.employee_id ,employees.title,employees.name,accounts.account_id, branch_id from employees full outer join accounts on employees.employee_id = accounts.emp_ID order by account_ID

58

Page 60: Bank Database (1)

Chapter 11- Nested Queries

1.) This query shows all the employee information of employees with yearly salary over 80000select * from employees where employee_id in (select employee_id from employees where yearly_salary >80000)

2.) This shows the account with the highest amount of transactionsselect account_id, type, amount from account_transaction where account_id =(select account_id from account_transaction where amount= (select max(amount)from account_transaction))

3.) These are the people who get paid more than the Loan administratorsselect name,title,yearly_salary from employees where yearly_salary >(select max(yearly_salary) from employees where title='Loan Administrator');

4.) Person with the highest loan amountselect loan_id,amount,duration_of_loan from loans where amount >(select avg(amount) from loans where type ='Fixed');

59

Page 61: Bank Database (1)

5.) This query can be used to find the name, account id, loan id and loan amount of a single entity based on their loan id.select a.customer_id, a.name, b.loan_id, b.amount from customers a, loans b where a.customer_id = b.loan_id and b.amount= (select amount from loans where loan_id = 100)

60

Page 62: Bank Database (1)

Chapter 12 – Views

1.) create view Branch_Information as select count(employee_id) as "Number Of employees", branch_location from employee_branch_location group by branch_locationNumber of employees per branch location

2.) customer info Viewcreate view Customer_INFO as select customers.name,customers.address,customers.customer_id, accounts.branch_id, accounts.type , accounts.web_id,accounts.web_password from customers inner join accounts on customers.customer_id = accounts.account_id

3.) This view contains Customer loan informationcreate view Customer_LOAN_INFO as select loans.loan_id, customers.name, customers.address, customers.home_phone, loans.amount from customers inner join loans on customers.customer_id = loans.loan_id

61

Page 63: Bank Database (1)

4.) This view shows customer transactions by namecreate view Customer_transactions as select customers.name,account_transaction.tellers_id, transaction_id,description from customers full outer join account_transaction on customers.customer_id = account_transaction.account_ID order by account_ID

62

Page 64: Bank Database (1)

5.) This query shows the years the customer has been with the bank, In the database every customer has opened their account in 2015 so the years with the bank column will be 0 for all customers.Create view customer_loyalty as select a.account_id, b.name, b.address, b.home_phone,round((sysdate-a.date_opened)/365) as "Years with bank" from accounts a, customers b where a.account_id = b.customer_id group by a.account_id , b.name,b.address,b.home_phone,a.date_opened

63

Page 65: Bank Database (1)

Chapter 13 – Comments

comment on table employee_branch_location is 'Was made By RushiParekh Last Modified 5/14/2015'

Same was done for all views and tables.

select * from user_tab_comments where comments is not null

64