Banking Database
Banking Database
requirements.
BRANCH (BRANCH_NAME: STRING, BRANCH-CITY: STRING, ASSETS: REAL)
ACCOUNT (ACCNO: INT, BRANCH-NAME: STRING, BALANCE: REAL)
DEPOSITOR (CUSTOMER-NAME: STRING, ACCNO: INT)
CUSTOMER (CUSTOMER-NAME: STRING, CUSTOMER-STREET: STRING, CITY:
STRING)
LOAN (LOAN-NO: INT, BRANCH-NAME: STRING, AMOUNT REAL)
BORROWER (CUSTOMER-NAME: STRING, LOAN-NO: INT)
(i) Create the above tables by properly specifying the primary keys and the foreign keys
(ii) Enter at least five tuples for each relation
(iii) Find all the customers who have at least two accounts at the Main branch.
(iv) Find all the customers who have an account at all the branches located in a specific city.
(v) Demonstrate how you delete all account tuples at every branch located in a specific city.
CREATE TABLE branch
(branch_name VARCHAR (15),
branch_city VARCHAR (15),
assets FLOAT(10,2),
PRIMARY KEY (branch_name) );
Description: The query is selecting the customer's name such that the account number associated
with name is in both the account table and depositor table and also the name of the branch in the
account table is B1 and then the tuples are being grouped by customer name in the depositor
table and also the customer name having count atleast equal to 2 are being selected.
iv. Find all the customers who have an account at all the branches located in a specific city.
mysql> SELECT d.customer_name
FROM account a,branch b,depositor d
WHERE b.branch_name=a.branch_name AND
a.accno=d.accno AND
b.branch_city='c3'
GROUP BY d.customer_name
HAVING COUNT(distinct b.branch_name)=(
SELECT COUNT(branch_name)
FROM branch
WHERE branch_city='c3');
Description: The query selects the customers from the depositor table such that branch name is in
both the branch table and also account table and the account number in the selected tuples is in
both account table and in depositor table and also the name of the branch city is 'c3'. The selected
tuples are grouped by the customer name of the depositor table whose count should be equal to
the count of the branch name in the branch table with branch city 'c3'.
v. Demonstrate how you delete all account tuples at every branch located in a specific city.
mysql> DELETE FROM account WHERE branch_name IN(SELECT branch_name FROM
branch WHERE branch_city='c5');
Query OK, 1 row affected (0.04 sec)
mysql>SELECT * FROM account;
Description: The inner query "SELECT branch_name FROM branch WHERE branch_city='c5' "
selects the branch names from the branch table where the branch city is c5. The selected tuples
are given as input to the outer query which deletes the tuples with the selected branch names.