0% found this document useful (0 votes)
7 views

Prog 5

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Prog 5

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

BANKING DATABASE

Consider the following database for a banking enterprise..

BRANCH(branch-name:string,branch-city:string,assets:real)

ACCOUNT(accno:int,branch-name:string,balance:real)

DEPOSITER(customer-name:string,accno:int)

CUSTOMER(customer-name:string,customer-street:string,customer-city:string)

LOAN(loan-number:int,branch-name:string,amount:real)

BORROWER(customer-name:string,loan-number:int)

1)create the above tables by properly specifying the primary keys and the foreign keys
2)enter at least five tupels for each relation
3)find all the customers who have at least two accounts at the main branch.
4)find all the customers who have an account at all the branches located in a specific city.
5)demonstrate how you delete all account tuples at every branch located in a specific city.

Answer…
create table branch5(branchname varchar(20),
branchcity varchar(20),
assets real,
constraint pkey1 primary key(branchname));

insert into branch5 values('Gandhinagar','dwd','10000');


insert into branch5 values('california','usa','20000');
insert into branch5 values('miraz','maharashtra','50000');
insert into branch5 values('cannaught','delhi','900000');
insert into branch5 values('necklace','hyderabad','900000');

create table account5(accno int,


branchname varchar(20),
balance real,
constraint pkey2 primary key(accno));

insert into account5 values('123','Gandhinagar','25000');


insert into account5 values('156','Gandhinagar','30000');
insert into account5 values('456','miraz','15000');
insert into account5 values('789','cannaught','25000');
insert into account5 values('478','necklace','48000');

1
create table customer5(customername varchar(20),
customerstreet varchar(20),
customercity varchar(20),
constraint pkey3 primary key(customername));

insert into customer5 values('Ramu','Gandhinagar','dwd');


insert into customer5 values('Kumar','miraz','maharashtra');
insert into customer5 values('John','cannaught','delhi');
insert into customer5 values('Mike','necklace','hyderabad');
insert into customer5 values('Sachin','california','usa');

create table depositor5(customername varchar(20),


accno int,
constraint pkey4 primary key(customername,accno),
constraint fkey1 foreign key(customername) references
customer5(customername),
constraint fkey2155 foreign key(accno) references account5(accno)on delete
cascade);

insert into depositor5 values('Ramu',123);


insert into depositor5 values('Ramu',156);
insert into depositor5 values('Kumar',456);
insert into depositor5 values('John',789);
insert into depositor5 values('Mike',478);

create table loan5(loanno int,


branchname varchar(20),
amount real,
constraint pkey5 primary key(loanno),
constraint fkey3 foreign key(branchname) references branch5(branchname));

insert into loan5 values('1111','Gandhinagar','250000');


insert into loan5 values('2222','miraz','350000');
insert into loan5 values('3333','cannaught','150000');
insert into loan5 values('4444','necklace','1500000');
insert into loan5 values('5555','california','7500000');

create table borrower5(customername varchar(20),


loanno int,
constraint pkey25 primary key(customername,loanno),
constraint fkey23 foreign key(customername) references
customer5(customername),
constraint fkey24 foreign key(loanno) references loan5(loanno));

2
insert into borrower5 values('Ramu',1111);
insert into borrower5 values('Kumar',2222);
insert into borrower5 values('John',3333);
insert into borrower5 values('Mike',4444);
insert into borrower5 values('Sachin',5555);

a>find all the customers who have an account at all the branches located in a specific
city.

SELECT C5.customername
FROM customer5 C5,depositor5 D5,account5 A5
WHERE C5.customername=D5.customername AND D5.accno=A5.accno AND
A5.branchname='Gandhinagar'
group by C5.customername HAVING COUNT(A5.accno)>=2;

b>find all the customers who have atleast two accounts at the main branch.

SELECT C5.customername FROM account5 A5,depositor5 D5,customer5 C5,branch5 B5


WHERE C5.customername=D5.customername AND D5.accno=A5.accno AND
A5.branchname=B5.branchname AND B5.branchcity='maharashtra'
GROUP BY C5.customername
HAVING(COUNT(distinct B5.branchname))=(SELECT COUNT(branchname) FROM
branch5
WHERE branchcity='maharashtra');

c>demonstrate how you delete all account tuples at every branch located in a specific
city.

DELETE FROM account5


WHERE branchname IN (SELECT branchname FROM branch5 WHERE
branchcity='maharashtra');

You might also like