You are on page 1of 5

Introduction

The idea is to develop a simple bank database that will keep track of all bank branches, employees, customers, accounts, etc. A Bank is an entity that contains the name, code and address of a bank. A bank can have multiple branches hence a branch can be defined as address of that branch and a branch code. There could be many accounts in a branch. An account can have account number as primary key, date of creation and amount in that account. A customer is a person who has an account in the bank; so it is necessary for the bank to keep the record of the customer. Hence customer is an entity, so the attributes of customer are: Name, address and phone number. Employee is a person working in the bank so the bank also keeps the record of his employee. The attributes of employee are employee number, name and address.

ENTITY RELATIONSHIP DIAGRAM FOR THE BANK DATABASE

Code Bank EMP_NO Name Name

Contact Street

City ZIP Code

Account No m Employee Address Address Br. Code 1 Account No Customer Address Phone No Name 1 m Branch m Account 1
Date of creation

Amount

Relations
Contact (Contact#, City, ZIP Code, Street) Bank (Code, Name, Contact#*, Br. Code*) Branch (Br. Code, Address, EMP_NO*) Employee (EMP_NO, Name, Address) Account (Account No, Amount, Date of creation) Customer (Account No*, Name, Address, Phone No)

SQL Code to Create the Tables

CREATE Table Contact ( Contact VARCHAR(20), City VARCHAR(20), ZIP Code NUMBER, Street VARCHAR(20) CONSTRAINT PRIMARY KEY(Contact#), )

CREATE Table Bank ( Code NUMBER, Name VARCHAR(20), Contact#* VARCHAR(20), Br. Code NUMBER, CONSTRAINT PRIMARY KEY(Code), CONSTRAINT FOREIGN KEY (Contact#*) REFERENCES Contact(Contact#), CONSTRAINT FOREIGN KEY (Br. Code*) REFERENCES Brach(Br. Code) )

CREATE Table Branch ( Br. Code NUMBER, Address VARCHAR(20), EMP_NO NUMBER, CONSTRAINT PRIMARY KEY(Br. Code), CONSTRAINT FOREIGN KEY (EMP_NO*) REFERENCES Employee(EMP_NO), )

CREATE Table Employee ( EMP_NO NUMBER, Address VARCHAR(20),

Name VARCHAR(20), CONSTRAINT PRIMARY KEY(EMP_NO), )

CREATE Table Account ( Account No NUMBER, Amount NUMBER, Date of creation DATE, CONSTRAINT PRIMARY KEY(Account No), )

CREATE Table Customer ( Account No NUMBER, Name VARCHAR(20), Address VARCHAR(20), Phone No NUMBER, CONSTRAINT PRIMARY KEY(Account No*), CONSTRAINT FOREIGN KEY (Account No*) REFERENCES Account(Account No), )

Some Queries
Find the name of customer whose account number is 456987? SELECT name FROM customer WHERE Account No ='456987';

Find number and address of employees who live in Ohrid? SELECT emp_no, name, address, FROM employee WHERE address like '%Ohrid';

You might also like