0% found this document useful (0 votes)
35 views27 pages

Labfile ADBMS

Uploaded by

Saurabh Sahu
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)
35 views27 pages

Labfile ADBMS

Uploaded by

Saurabh Sahu
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/ 27

INDEX

S.NO CONTENTS DATE OF DATE OF REMARKS


EXP. SUBMISSION
1. For all customers who have a loan from the bank, find 11-SEP-24
their names, loan numbers and loan amount.

2. Find the customer names, loan numbers, and loan 11-SEP-24


amounts for all loans at the Perry ridge branch.
3. Find the names of all branches that have assets 11-SEP-24
greater than at least one branch located in Brooklyn.
4. Find the names of all branches in the loan rela on 11-SEP-24

5. Find all loan numbers for loans made at the Perry 11-SEP-24
ridge branch with loan amounts greater than $1200.

6. Find the avg balance for all accounts. 23-SEP-24

7. Find all loan numbers that appear in the loan relation 23-SEP-24
with null values for amount.

8. Write the name of all customers whose street address 23-SEP-24


includes the substring ‘Main’.

9. Find employee name and salary from emp table 23-SEP-24


and sal multiplied by 100 with new name of the
column .
10. Find list in alphabet order who has loan from 23-SEP-24
Perryridge
11. Select opera on ,union, intersec on and set 23-SEP-24
difference.

12. Find all customer who have both a loan and an 25-SEP-24
account at the bank.

13. Find all customer who have an account but no loan at 25-SEP-24
the bank
14. Find total account balance at each branch. 25-SEP-24

15. Find the average account balance at each branch 25-SEP-24


16. Delete all account tuples in the Perryridge branch 30-SEP-24

17. Delete all loans amounts between 1300 and 1500. 30-SEP-24
18. Delete all account tuples at every branch located in 30-SEP-24
Needham.
19. Insert a new record into account where account no. 30-SEP-24
A-9732 at the Perry Ridge Branch & that is has a
balance 0.
20. Update balance Value of the account table by 30-SEP-24
Mul plica on of 1.05 where balance is greater than
equal to 700.

21. Create account table with two a ributes. 5 a.) 30-SEP-24


Account no of char type. b.) Balance of int type.

22. Find the average balance for each customer who lives 30-SEP-24
in Harrison and has at least three accounts.

23. Find the number of depositor from each 30-SEP-24


branch.
24. Insert two rows in the table with different values and 30-SEP-24
display.

25. For all customers who have a loan from the bank, find 30-SEP-24
their names, loan numbers, and loan amount with
renaming the tables.

26. Write a query to display dis nct a ributes from 7-OCT-24


EMP table.

27. Write a query to display all records where 7-OCT-24


sal>3000
28. Write a query to find all employee name and 7-OCT-24
salary whose salary is greater than 1000 and less
than 3000.

29. Find all customers who do have a loan at the 7-OCT-24


bank, but do not have a account at the bank.
30. Write a query to find ename and salary from EMP 16-OCT-24
table and salary*100 with renaming of column.

31. Write a query to find employee name and salary 16-OCT-24


from EMP table ordered by salary.

32. Write a query to display all aggrega on opera on 16-OCT-24


in the EMP table for the a ribute salary.

33. Write a query to select a ributes from EMP table 16-OCT-24


with arithme c opera on on salary a ributes of
EMP table.

34. Write a query to display EMPNO, ENAME, SAL 16-OCT-24


from emp table.
35. Write a query to display all records of 7-OCT-24

emp table
Bank database Schema:
Account1 table schema:
Account1_schema=(account_number; branch_name, balance)
Sql query:
Create table account1(account_number char(15),
Branch_name varchar(15),
Balance numeric(12, 2),
Primary key(account_number));

Branch table schema:


Branch_schema=(branch_name, branch_city, assets)
Sql query:
Create table Branch(branch_name varchar(10),
Branch_city varchar(10),
Assets integer,
Primary key(branch_name));
Loan table schema:
Loan_schema=(loan_number char(10),
Branch_name varchar(10),
Amount numeric(12, 2),
Primary key(loan_number));
Sql query:
Create table loan (loan_Number char(10),
branch_name varchar(10),
amount numeric(12,2),
primary key(loan_number));

Customer table schema:


Customer_schema=(customer_name varchar(10),
Customer_street varchar(10),
Customer_city varchar(10),
Primary key(customer_name));
Borrower table schema(customer_name varchar(10),
Loan_number char(10),
Primary key(customer_name, loan_number),
FOREIGN key(customer_name) REFERENCES
customer(customer_name),
FOREIGN key(loan_number) REFERENCES
loan(loan_number));

Depositor table schema


Depositor_schema=(customer_name varchar(10),
Account_number char(15),
Primary key(customer_name, account_number),
FOREIGN KEY (customer_name) REFERENCES
customer(customer_name),
FOREIGN KEY(account_number) REFERENCES
account1(account_number));
Inserting Data into Tables:
Inserting values to account table:

insert into account values("A-101", "Downtown", 500);


insert into account values("A-102", "Perryridge", 400);
insert into account values("A-201", "Brighton", 900);
insert into account values("A-215", "Mianus", 700);
insert into account values("A-217", "Brighton", 750);
insert into account values("A-222", "Redwood", 700);
insert into account values("A-305", "Round Hill", 350);
Inserting values to Branch table:
insert into branch values("Brighton","Brooklyn", 710000);
insert into branch values("Downtown","Brooklyn", 9000000);
insert into branch values("Mianus","Horseneck", 400000);
insert into branch value("North Town","Rye", 3700000);
insert into branch value("Perryridge","Horseneck", 1700000);
insert into branch value("Pownal","Bennington", 300000);
insert into branch value("Redwood","Palo Alto", 2100000);
insert into branch value("Round Hill","Horseneck", 8000000);

Inser ng values to customer Table:


insert into customer values("Smith", "North", "Rye");

insert into customer values("Brooks", "Senator", "Brooklyn");

insert into customer values("Gleen", "Sand Hill", "Woodside");

insert into customer values("Green", "Walnut", "Stamford");

insert into customer values("Turner", "Putnam", "Stamford");

insert into customer values("Jackson", "Dupont", "Woodside");

insert into customer values("Johnson", "Alma", "Palo Alto");

insert into customer values("Curry", "North", "Rye");

insert into customer values("Jones", "Main", "Harrison");

insert into customer values("Adams", "Spring", "Pi sfield");


insert into customer values("Lindsay", "Park", "Pi sfield");

insert into customer values("Hayes", "Main", "Harrison");

insert into customer values("Williams", "Nassau", "Princeton");

inserting values to loan :


insert into loan values("L-11", "Round Hill", 900);
insert into loan values("L-14", "Downtown", 1500);
insert into loan values("L-15", "Perryridge", 1500);
insert into loan values("L-16", "Perryridge", 1300);
insert into loan values("L-17", "Downtown", 1000);
insert into loan values("L-23", "Redwood", 2000);
insert into loan values("L-95", "Mianus", 500);
Inser ng value to borrower Table:
insert into borrower values("Jackson", "L-14");

insert into borrower values("Jones", "L-17");

insert into borrower values("Smith", "L-11");

insert into borrower values("Hayes", "L-15");

insert into borrower values("Adams", "L-16");

insert into borrower values("Smith", "L-23");

insert into borrower values("Curry", "L-93");

insert into borrower values("Williams", "L-17");

inserting values to depositor:


insert into depositor values("Hayes", "A-102");

insert into depositor values("Johnson", "A-101");

insert into depositor values("Johnson", "A-201");

insert into depositor values("Jones", "A-217");

insert into depositor values("Lindsay", "A-222");

insert into depositor values("Smith", "A-215");

insert into depositor values("Turner", "A-305");


1. For all customers who have a loan from the bank, find their names, loan numbers and loan
amount.

SQL :
select customer_name, borrower.loan_number, amount
from borrower, loan
where borrower.loan_number = loan.loan_number;

2. Find the customer names, loan numbers, and loan amounts for all loans at the Perryridge
branch.
SQL:
select customer_name, Borrower.loan_number, amount
from Borrower, loan
where Borrower.loan_number = loan.loan_number and
branch_name = "Perryridge";

3. Find the names of all branches that have assets greater than at least one branch located in
Brooklyn.
SQL:
select distinct T.branch_name
from branch as T, branch as S
where T.assets > S.assets and S.branch_city = "Brooklyn";
4. Find the names of all branches in the loan rela on
SQL : select branch_name from loan;

5. Find all loan numbers for loans made at the Perryridge branch with loan amounts greater
than $1200.

SQL:
select loan_number
from loan
where branch_name = "Perryridge" and amount > 1200;

6. Find the avg balance for all accounts.


SQL : Select avg (balance) from account;

7. Find all loan numbers that appear in the loan relation with null values for amount.
SQL: select loan_number
from loan
where amount is null;
8. Provide an SQL with example which will rename the relational name.
SQL:
select customer_name, borrower.loan_number as loan_id, amount
from borrower, loan
where borrower.loan_number = loan.loan_number;

9. Write the name of all customers whose street address includes the substring ‘Main’.
select customer_name
from customer
where customer_street like '%Main%';

10. Find list in alphabet order who has loan from


Perryridge

SQL :

select distinct customer_name

from borrower, loan

where borrower.loan_number = loan.loan_number and

branch_name = "Perryridge"

order by customer_name;
11. Select operation ,union, intersection and set difference.
UNION:
SQL:

(select customer_name from depositor)

union

(select customer_name from borrower);

Intersect:
SQL:
SELECT DISTINCT d.customer_name
FROM depositor d
INNER JOIN borrower b ON d.customer_name = b.customer_name;
Difference:
SQL:
select distinct customer_name from depositor where customer_name not in (select
customer_name from borrower);

12. Find all customer who have both a loan and an account at the bank.
SQL :
select distinct customer_name from borrower where customer_name in (select
customer_name from depositor);

13. Find all customer who have an account but no loan at the bank
SQL :
select depositor.customer_name as d_CN from depositor
left join borrower on depositor.customer_name = borrower.customer_name
where borrower.customer_name is null;
14. Find total account balance at each
branch.

SQL :
select branch_name, sum(balance)
from account1
group by branch_name;

15. Find the average account balance at each


branch
SQL :
select branch_name, avg (balance)
from account1
group by branch_name;

16. Delete all account tuples in the Perryridge branch


SQL :

delete from account1


where branch_name = "Perryridge";

Before:
After:

17. Delete all loans amounts between 1300 and 1500.


SQL:
delete from loan
where amount between 1300 and 1500;
Before:

After query:

18. Delete all account tuples at every branch located in Needham.


SQL:

delete from account


where branch_name in (select branch_name
from branch
where branch_city = "Needham");
19. Insert a new record into account where account no. A-9732 at the Perry Ridge Branch & that
is has a balance 0.
SQL:
insert into account1 values("A-9732", "Perryridge", 0);
Before:

A er query:

20. Update balance Value of the account table by Muliplica on of 1.05 where balance is greater
than equal to 700.
SQL:
update account set balance = balance * 1.05 where balance >= 1000

Before:
A er query:

21. Create account table with two a ributes. a.) Account no of char type. b.) Balance of int type.
SQL:
create table Account2 (account_number char(15), balance integer, primary
key(account_number));

22. Find all customers who do have a loan at the bank, but do not have an account at the
bank.

SQL :
SELECT DISTINCT borrower.customer_name
FROM borrower
LEFT JOIN depositor ON borrower.customer_name = depositor.customer_name
WHERE depositor.customer_name IS NULL;

23. Find the average balance for each customer who lives in Harrison and has at least three
accounts.

SQL :

select depositor.customer_name, avg(balance) from depositor, customer, account1


where depositor.account_number = account1.account_number and
depositor.customer_name = customer.customer_name and customer_city = "Harrison"
group by depositor.customer_name;
24. Insert two rows in the table with different values and display.
create table Student1(rollno integer, name char(15), branch varchar(10), primary
key(rollno));

insert into student1 values(101, "Saurabh", "MCA");

insert into student1 values(102, "Sakshi", "MBA");

25. For all customers who have a loan from the bank, find their names, loan numbers, and
loan amount with renaming the tables.

SQL :
select customer_name, T.loan_number, S.amount
from borrower as T, loan as S
where T.loan_number = S.loan_number;
Employee Database
CREATE TABLE emp (

empno decimal(4,0) NOT NULL,


ename varchar(10) default NULL,
job varchar(9) default NULL,
mgr decimal(4,0) default NULL,
hiredate date default NULL,
sal decimal(7,2) default NULL,
comm decimal(7,2) default NULL,
deptno decimal(2,0) default NULL,
PRIMARY KEY(empno)
);
Inser ng values in Table:
INSERT INTO emp VALUES ('7369','SMITH','CLERK','7902','1980-12-17','800.00',NULL,'20');
INSERT INTO emp VALUES ('7499','ALLEN','SALESMAN','7698','1981-02-
20','1600.00','300.00','30');
INSERT INTO emp VALUES ('7521','WARD','SALESMAN','7698','1981-02-
22','1250.00','500.00','30');
INSERT INTO emp VALUES ('7566','JONES','MANAGER','7839','1981-04-
02','2975.00',NULL,'20');
INSERT INTO emp VALUES ('7654','MARTIN','SALESMAN','7698','1981-09-
28','1250.00','1400.00','30');
INSERT INTO emp VALUES ('7698','BLAKE','MANAGER','7839','1981-05-
01','2850.00',NULL,'30');
INSERT INTO emp VALUES ('7782','CLARK','MANAGER','7839','1981-06-
09','2450.00',NULL,'10');
INSERT INTO emp VALUES ('7788','SCOTT','ANALYST','7566','1982-12-
09','3000.00',NULL,'20');
INSERT INTO emp VALUES ('7839','KING','PRESIDENT',NULL,'1981-11-
17','5000.00',NULL,'10');
INSERT INTO emp VALUES ('7844','TURNER','SALESMAN','7698','1981-09-
08','1500.00','0.00','30');
INSERT INTO emp VALUES ('7876','ADAMS','CLERK','7788','1983-01-12','1100.00',NULL,'20');
INSERT INTO emp VALUES ('7900','JAMES','CLERK','7698','1981-12-03','950.00',NULL,'30');
INSERT INTO emp VALUES ('7902','FORD','ANALYST','7566','1981-12-03','3000.00',NULL,'20');
INSERT INTO emp VALUES ('7934','MILLER','CLERK','7782','1982-01-23','1300.00',NULL,'10');

1. Write a query to display dis nct a ributes from EMP table.


SQL:
SELECT DISTINCT empno, ename, job, mgr, hiredate, sal, comm, deptno
FROM emp;

2. Write a query to display all records where sal>3000.


SQL:
SELECT * FROM emp WHERE sal > 3000;
3. Write a query to find all employee name and salary whose salary is greater than 1000
and less than 3000.

SQL: select ename, sal from emp where sal>1000 and sal<3000;

4. Write a query to select emp, employee name and salary where salary is
greater than or equal to 2000 and add 500 Rs extra and display.

SQL:
select ename, sal+500 from emp where sal>=2000 ;

5. Write a query to find ename and salary from EMP table and salary*100 with renaming of
column.
SQL:
select ename, sal, sal*100 from emp ;
6. Write a query to find employee name and salary from EMP table ordered
by salary.
SQL:
select ename, sal from emp order by sal;

7. Write a query to display all aggrega on opera on in the EMP table for
the a ribute salary.
SQL:
select avg(sal) from emp;

select MAX(sal) from emp;

select SUM(sal) from emp;

select MIN(sal) from emp;

select count(*) from emp;


8. Write a query to select a ributes from EMP table with arithme c
opera on on salary a ributes of EMP table.
SQL:
select ename, sal, sal*10, sal/10, sal-1000, sal+5000 from emp;

9. Write a query to display EMPNO, ENAME, SAL from emp table.


SQL:
select empno, ename, sal from emp;
10. Write a query to display all records of emp table
SQL:
SELECT * FROM EMP;

You might also like