0% found this document useful (0 votes)
1K views3 pages

Bank Database

The document describes the creation of a BANK database in MySQL. It defines tables for customers, accounts, branches, and loans. It then provides examples of 6 queries on this database: 1) finding customers with loan amounts over $10,000, 2) finding customers with accounts but no loans, 3) finding customers with both accounts and loans, 4) finding customers with loans from the Chennai branch, 5) finding customers with savings accounts, and 6) finding the total loan amount at the Pune branch.

Uploaded by

Vaibhav Acharya
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views3 pages

Bank Database

The document describes the creation of a BANK database in MySQL. It defines tables for customers, accounts, branches, and loans. It then provides examples of 6 queries on this database: 1) finding customers with loan amounts over $10,000, 2) finding customers with accounts but no loans, 3) finding customers with both accounts and loans, 4) finding customers with loans from the Chennai branch, 5) finding customers with savings accounts, and 6) finding the total loan amount at the Pune branch.

Uploaded by

Vaibhav Acharya
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

/* BANK DATABASE

Name : Lokesh Deshpande Class : SYBCS(A)

Roll No. : 318 July 12, 2011

1
*

BANK DATABASE*/
BANK Database creation and implementation::-->

mysql> create database BANK; Query OK, 1 row affected (0.00 sec) mysql> use BANK; Database changed mysql> * Creation of tables in BANK Database::-->

mysql> create table customer(cust_no int primary key,cust_name char(20), cust_street char(20),cust_city varchar(20)); Query OK, 0 rows affected (0.08 sec) mysql> create table account(acc_no int primary key,acc_type char(20), balance float(8,2),cust_no int,foreign key(cust_no) references customer(cust_no)); Query OK, 0 rows affected (0.47 sec) mysql> create table branch(branch_no int primary key,branch_name char(20), branch_city varchar(20),cust_no int,foreign key(cust_no) references customer(cust_no),acc_no int,foreign key(acc_no) references account(acc_no)); Query OK, 0 rows affected (0.56 sec)

mysql> create table loan(loan_no int primary key,loan_amt double(9,2), no_of_years int,cust_no int,foreign key(cust_no) references customer(cust_no), branch_no int,foreign key(branch_no)references branch(branch_no)); Query OK, 0 rows affected (0.07 sec) * QUERY 1::--> Find out customer name having loan amt >10000.

mysql> select cust_name from customer,loan where loan_amt>10000 and customer.cust_no = loan.cust_no; +-----------+ | cust_name | +-----------+ | ABC | | PQR | | XYZ | +-----------+ 3 rows in set (0.00 sec) * QUERY 2::--> Select customers having account but not loan.

mysql> select customer.cust_no from customer,account where customer.cust_no = account.cust_no not in(select customer.cust_no from customer,loan where customer.cust_no = loan.cust_no); Empty set (0.00 sec) * QUERY 3::--> Select customers having account as well as loan.

mysql> select customer.cust_no from customer,account where customer.cust_no = account.cust_no in(select customer.cust_no from customer,loan where customer.cust_no = loan.cust_no); +---------+ | cust_no | +---------+ | 1 | +---------+ 1 row in set (0.00 sec) * QUERY 4::--> Find out customer names having loan at Chennai branch.

mysql> select cust_name from customer,loan,branch where branch_city = Chennai and customer.cust_no = branch.cust_no and loan.cust_no = customer.cust_no; 2

+-----------+ | cust_name | +-----------+ | PQR | +-----------+ 1 row in set (0.00 sec) * QUERY 5::--> Find out customer names having Saving account.

mysql> select cust_name from customer,account where acc_type = Saving and customer.cust_no = account.cust_no; +-----------+ | cust_name | +-----------+ | ABC | | PQR | | XYZ | +-----------+ 3 rows in set (0.00 sec) * QUERY 6::--> Find out the total loan amount at Pune Branch.

mysql> select sum(loan_amt) from loan,branch where branch_city = Pune and loan.cust_no = branch.cust_no; +---------------+ | sum(loan_amt) | +---------------+ | 30000.00 | +---------------+ 1 row in set (0.00 sec)

You might also like