Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

EXP NO:06

DATE: 23-03-2021

SQL QUERIES - BANK DATABASE


AIM:
To create a database for Banking domain and to execute simple and nested queries
in sql.

PROBLEM DEFINITION:
Create tables for the Banking system as per the constraints given and execute
queriesas per the requirements mentioned.

TABLE: BRANCH
Name Null? Type
--------------------------------- -------- - - --------------------------
BNAME NOT NULL VARCHAR2(15)
CITY VARCHAR2(15)
BID NOT NULL NUMBER(4)

TABLE: CUSTOMERS
Name Null? Type
------------------------- ------------- -------- ----------------------------
CID NOT NULL NUMBER(4)
CNAME VARCHAR2(20)
AGE NUMBER(2)
LOCATION VARCHAR2(20)
BNAME VARCHAR2(15)
ACTNO VARCHAR(4)

TABLE: LOAN
Name Null? Type
------------------------------- ---------- -------- ----------------------------
CID NUMBER(4)
AMOUNT NUMBER(8)
INTEREST NUMBER(2,2)
ACTNO VARCHAR(4)

TABLE :DEPOSIT
Name Null? Type
------------------------------- ------ -------- ----------------------------
ACTNO VARCHAR2(4)
AMOUNT NUMBER(8,2)
ADATE DATE
CID NUMBER(4)

PROCEDURE:
TABLE:BRANCH
create table branch(bname varchar(20) not null,city varchar(20),BID integer not null);
insert into branch values('Chrompet','Chennai',7847762);
insert into branch values('Pallavaram','Chennai',987654);
insert into branch values('Bombay','Bombay',1234567);
insert into branch values('Tambaram','Chennai',4456798);
insert into branch values('Pallavaram','Mumbai',5438123);
insert into branch values('Delhi','Delhi',56421098);

TABLE:CUSTOMERS
create table customers(CID integer not null,cname varchar(10),age integer,location
varchar(10),bname varchar(10),actno varchar(20));
insert into customers values(4321,'prem',20,'Delhi','Chrompet','987654321');
insert into customers values(5678,'sunil',24,'Chennai','Pallavaram','123456789');
insert into customers values(3456,'vijay',23,'Bombay','Bombay','7465413356');
insert into customers values(6543,'anil',25,'Chennai','Tambaram','46789013478');
insert into customers
values(5320,'Kamalika',30,'Pallavaram','Pallavaram','54217890654');
insert into customers values(1289,'Snekha',26,'Delhi','Delhi','75153420866');
TABLE:LOAN
create table loan(CID integer,amount integer,interest integer,actno varchar(15));
insert into loan values(4321,50000,10,'987654321');
insert into loan values(5678,60000,20,'123456789');
insert into loan values(3456,70000,30,'7465413356');
insert into loan values(6543,80000,40,'46789013478');
insert into loan values(5320,90000,50,'54217890654');
insert into loan values(1289,50000,30,'75153420866');

TABLE:DEPOSIT
create table deposit(actno varchar(20),amount integer,Adate date);
insert into deposit values('987654321',50000,'12-dec-2010');
insert into deposit values('123456789',60000,'13-oct-2005');
insert into deposit values('7465413356',70000,'08-apr-2013');
insert into deposit values('46789013478',80000,'31-dec-2016');
insert into deposit values('54217890654',90000,'06-jun-2006');
insert into deposit values('75153420866',50000,'04-jun-2011');

Queries with Update:


1. Give 10 % interest to all depositors.
update deposit set amount=amount+(amount*0.1);
select * from deposit;

2. Give 10 % interest to all depositors having branch name=’tambaram’;


update deposit set amount=amount+(amount*0.1) where actno=(select actno from
customers where bname='Tambaram');
select * from deposit;

3. Give 10 % interest to all depositors living in delhi


update deposit set amount=amount+(amount*0.1) where actno in (select actno
from customers where location='Delhi');
select * from deposit;
4. Give 10 % interest to all depositors living in delhi and having branch city in
Bombay
update deposit set amount=amount+(amount*0.1) where actno=(select actno from
customers where location='Delhi' and bname='Bombay');
select * from deposit;

5. Update the deposit amount of prem to sunil


update deposit set amount=(select amount from deposit where actno=(select actno
from customers where cname='prem')) where actno=(select actno from customers
where cname='sunil');
select * from deposit;

6. Deposit the sum of the deposits of sunil and vijay in the account of prem
update deposit set amount=(select amount from deposit where actno=(select actno
from customers where cname='vijay'))+(select amount from deposit where
actno=(select actno from customers where cname='sunil')) where actno=(select
actno from customers where cname='prem');
select * from deposit;

7. Transfer Rs.10 from the account of anil to the account of sunil


update deposit set amount=amount-10 where actno=(select actno from customers
where cname='anil');
update deposit set amount=amount+10 where actno=(select actno from customers
where cname='sunil');
select * from deposit;

8.Replace all the customers names with first character initial letter and others in
lowercase.
update customers set cname=initcap(cname);
select * from customers;

8. Add a column for account starting date-accdate


alter table deposit add accdate date;
update deposit set accdate='01-jan-2008' where actno='987654321';
update deposit set accdate='08-jul-2004' where actno='123456789';
update deposit set accdate='19-may-2010' where actno='7465413356';
update deposit set accdate='06-nov-2008' where actno='46789013478';
update deposit set accdate='27-mar-2000' where actno='54217890654';
update deposit set accdate='18-feb-2007' where actno='75153420866';
select * from deposit;

Different forms of data retrieval(using nested queries):

9. Find out the number of customers starts with K


select cname from customers where cname like 'K%';

10.List all the customers with their customer id and account no


select CID,actno from customers;

11.List the customers of Pallavaram Branch;


select * from customers where bname='Pallavaram';

12.Give account number and deposit amount of customers having account


between 1 st jan and 31 dec 2010.
select * from deposit where Adate between '01-jan-2010' and '31-dec-2010';

14.List out the customer name and customer id in descending order based on the cid.
select cname,cid from customers order by cid desc;

15.List the customer name and their account numbers who stay in either Chennai or
delhi.
select cname,actno from customers where location= 'Delhi' or location='Chennai';

16.Find all the customers whose city name starts with the letter d.
select * from customers where location like 'D%';

17.List all the senior citizen’s account number with the title ACTNO-SNO
select * from customers where age>=60;

18.List the senior citizens of chrompet branch.


select * from customers where age>=60 and bname='Chrompet';

19.List the customer details who is having account in their own native .
select * from customers where location=bname;

20.Find the names of all the customers having ‘a’ as the third letter in their names.
select * from customers where cname like '__a%';

21.Find all the customers whose city names ends with the letter ‘l’ third from the last.
select * from customers where location like '%l__';

22.List the cuctomer details those who do not live in pallavaram.


select * from customers where not location='Pallavaram';

23.Print the customer details in following format.


“Raj is having account in pallavaram and living in saidapet”
select cname||' is having the account in ' ||bname ||' and living in ' ||location from
customers;

24. List the customer name and age with their email id .Give each customer an
email id.The username should be the cnamebname@idbi.ocm. User name should be in
lowercase.
alter table customers add emailid varchar(30);
update customers set emailid=lower(cname||bname||'@idbi.com');
select cname,age,emailid from customers;

25.Count the total number of branch cities


select city,count(*) from branch group by city;

26.Find the minimum and maximum deposited amount and rename that as
least_deposit and maximum deposit.
select min(amount) "least deposit",max(amount) "max deposit" from deposit;
27.Count the total number of customer cities.
select city,count(*) from branch group by city;

28.Give branch name and branch wise deposit.


select bname,sum(amount) from deposit d,customers c where d.actno=c.actno
group by bname;

29. List the total number of branches in Chennai.


select bname,city from branch where city='Chennai';

30. List the total number of branches in each city.


select city,count(*) from branch group by city;

OUTPUT:

You might also like