0% found this document useful (0 votes)
68 views7 pages

Iit2021034 Assignment DBMS

This document contains the code for 8 queries performed on tables created in a banking database. The tables store information about branches, customers, loans, accounts, and their relationships. The queries find customers that have loans or accounts in a specific city, loans over a certain amount at a branch, accounts at a branch without loans, the largest loan amount, customers with multiple accounts at a branch, branches with greater assets than others, updating account balances by different percentages, and customers with accounts at all branches in a city.

Uploaded by

Ujjwal
Copyright
© © All Rights Reserved
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)
68 views7 pages

Iit2021034 Assignment DBMS

This document contains the code for 8 queries performed on tables created in a banking database. The tables store information about branches, customers, loans, accounts, and their relationships. The queries find customers that have loans or accounts in a specific city, loans over a certain amount at a branch, accounts at a branch without loans, the largest loan amount, customers with multiple accounts at a branch, branches with greater assets than others, updating account balances by different percentages, and customers with accounts at all branches in a city.

Uploaded by

Ujjwal
Copyright
© © All Rights Reserved
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/ 7

DBMS LAB ASSIGNMENT -4

IIT2021034 UJJWAL PANDRAM

TABLES CREATED INITIALLY ARE :

Branch :

Customer :

Loan :

Borrower :

Account :

Depositor :
QUESTION 1:

Find the names of all customers who have a loan, an account, or both, from the bank and
who live in city Brooklyn.

QUERY :

RESULT :

QUESTION 2 :

Find the names of all customers who have a loan at the Perryridge branch of amount greater
than $2000.

QUERY :

RESULT :

QUESTION 3:

Find the names of all customers who have an account at the Perryridge branch but do not
have a loan at any branch of the bank.

QUERY :

RESULT :
QUESTION 4:

Find the largest loan amount.

QUERY :

RESULT :

QUESTION 5:

Find all customers who have at least two accounts at the perryridge branch.

QUERY :

RESULT :

QUESTION 6;

Find all branches that have greater assets than some branch located in Brooklyn.

QUERY :

RESULT :
QUESTION 7 :

Increase all accounts with balances over $10,000 by 6%, all other accounts receive 5%.

QUERY :

RESULT :

QUESTION 8 :

Find all customers who have an account at all the branches located in Brooklyn.

QUERY :

RESULT :

CODE :

CREATE TABLE branch( branch_name varchar(255) PRIMARY KEY, branch_city varchar(255), assets

int
);

CREATE TABLE customer( customer_name varchar(255) PRIMARY KEY, customer_street

varchar(255), customer_city varchar(255)

);

CREATE TABLE loan( loan_number int PRIMARY KEY, branch_name varchar(255), amount int,

FOREIGN KEY (branch_name) references branch(branch_name)

);

CREATE TABLE borrower( customer_name varchar(255), loan_number varchar(255),

FOREIGN KEY (customer_name) REFERENCES customer(customer_name),

FOREIGN KEY (loan_number) REFERENCES loan(loan_number)

);

CREATE TABLE account( account_number int PRIMARY KEY, branch_name varchar(255), balance int,

FOREIGN KEY (branch_name) REFERENCES branch(branch_name)

);

CREATE TABLE depositor( customer_name varchar(255), account_number int,

FOREIGN KEY (customer_name) REFERENCES customer(customer_name),

FOREIGN KEY (account_number) REFERENCES account(account_number)

);

INSERT into branch(branch_name,branch_city,assets)VALUES ('sbranch','bvrm',1);

INSERT into branch(branch_name,branch_city,assets)VALUES ('ubranch','bvrm',5);

INSERT into branch(branch_name,branch_city,assets)VALUES ('jbranch','brooklyin',3);

INSERT into branch(branch_name,branch_city,assets)VALUES ('Perryridge','hyd',4);

INSERT into customer(customer_name,customer_street,customer_city)VALUES ('sujitha','mystreet','bvrm');

INSERT into customer(customer_name,customer_street,customer_city)VALUES ('sudheer','thstreet','hyd');

INSERT into customer(customer_name,customer_street,customer_city)VALUES

('purna','hnstreet','brooklyin');

INSERT into loan(loan_number,branch_name,amount)VALUES ('1','sbranch','10000');

INSERT into loan(loan_number,branch_name,amount)VALUES ('2','ubranch','15000');

INSERT into loan(loan_number,branch_name,amount)VALUES ('3','jbranch','20000');

INSERT into loan(loan_number,branch_name,amount)VALUES ('4','Perryridge','25000');

INSERT into borrower(customer_name,loan_number)VALUES ('sudheer',3);

INSERT into borrower(customer_name,loan_number)VALUES ('sujitha',4);


INSERT into account(account_number,branch_name,balance)VALUES (11,'sbranch',10000);

INSERT into account(account_number,branch_name,balance)VALUES (12,'jbranch',8000);

INSERT into account(account_number,branch_name,balance)VALUES (13,'Perryridge',6000);

INSERT into account(account_number,branch_name,balance)VALUES (14,'Perryridge',15000);

INSERT into account(account_number,branch_name,balance)VALUES (15,'Perryridge',20000);

INSERT into depositor(customer_name,account_number)VALUES ('sujitha',11);

INSERT into depositor(customer_name,account_number)VALUES ('sudheer',12);

INSERT into depositor(customer_name,account_number)VALUES ('purna',13);

INSERT into depositor(customer_name,account_number)VALUES ('purna',14);

INSERT into depositor(customer_name,account_number)VALUES ('sudheer',15);

-- Find the names of all customers who have a loan, an account,

-- or both, from the bank and who live in city Brooklyn.

SELECT customer_name

FROM borrower

WHERE loan_number IN (SELECT loan_number FROM loan WHERE branch_name IN

(SELECT branch_name FROM branch WHERE branch_city = 'brooklyin')) OR customer_name IN (SELECT

customer_name FROM depositor WHERE account_number IN

(SELECT account_number FROM account WHERE branch_name IN

(SELECT branch_name FROM branch WHERE branch_city = 'brooklyin'))); -- Find the names of all customers

who have a loan at the Perryridge branch of amount

-- greater than $2000.

SELECT customer_name FROM borrower

WHERE loan_number IN(SELECT loan_number FROM loan WHERE branch_name='Perryridge' AND amount>2000);

-- Find the names of all customers who have an account at the Perryridge branch but do not

-- have a loan at any branch of the bank.

SELECT DISTINCT customer_name FROM depositor

WHERE account_number IN(SELECT account_number FROM account WHERE branch_name='Perryridge')

AND

customer_name NOT IN (SELECT customer_name FROM borrower);

-- Find the largest loan amount.

SELECT max(amount) FROM loan;

-- Find all customers who have at least two accounts at the perryridge branch.
SELECT customer_name FROM depositor WHERE

account_number IN

(SELECT account_number FROM account WHERE branch_name = 'Perryridge'

GROUP BY branch_name HAVING COUNT (account_number) >= 2 );

-- Find all branches that have greater assets than some branch located in Brooklyn.

SELECT branch_name FROM branch

WHERE assets > (SELECT assets FROM branch where branch_city='brooklyin');

-- Increase all accounts with balances over $10,000 by 6%, all other accounts receive 5%.

UPDATE account

SET balance =

CASE

WHEN balance > 10000 THEN balance * 1.06

ELSE balance * 1.05

END;

SELECT * FROM account;

-- Find all customers who have an account at all the branches located in Brooklyn.

SELECT d.customer_name

FROM depositor d

JOIN account a ON d.account_number = a.account_number

JOIN branch b ON a.branch_name = b.branch_name

WHERE b.branch_city = 'brooklyin'

GROUP BY d.customer_name

HAVING COUNT(DISTINCT b.branch_name) = (

SELECT COUNT(*)

FROM branch

WHERE branch_city = 'brooklyin'

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy