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

DBMS_P_SHITS[1]

The document outlines practical questions related to PostgreSQL, focusing on various database schemas including Employee, Investor, Project, Movie, Branch, and Person. It provides SQL queries for data manipulation and retrieval, such as listing employees, counting loan applications, and updating records. Additionally, it emphasizes the relationships between different entities and includes tasks like deleting records based on certain conditions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

DBMS_P_SHITS[1]

The document outlines practical questions related to PostgreSQL, focusing on various database schemas including Employee, Investor, Project, Movie, Branch, and Person. It provides SQL queries for data manipulation and retrieval, such as listing employees, counting loan applications, and updating records. Additionally, it emphasizes the relationships between different entities and includes tasks like deleting records based on certain conditions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 41

Q.

1) Practical Questions on PostgresSQL [Marks 10]


Consider the following database
Employee (emp_id, emp_name, address, bdate)
Investor (inv_no, inv_name, inv_date, inv_amt)
An employee may invest in one or more investments;
hence he can be an investor. But an
investor need not be an employee of the firm.
Assume appropriate data types for all the attributes.
I= invester, e=employee
create table e(emp_id int primary key,emp_name
varchar(20),address text,bdate date);

create table i(inv_name varchar(30),inv_no int primary


key,inv_date date,inv_amt numeric(8),emp_id int
references e on delete cascade);

Q1)
a) List the distinct names of customers who are either
employees, or investors or both.
A=select emp_name from e,i where e.emp_id=i.emp_id
union select emp_name from e;

b) List the employees who are living in pune.


B=select * from e where address = ‘pune';

c) Find the count of employee area wise


C=select e_name,count(*) from person group by
e_name;

d)Delete information of Investors whose amount is less


than 10,000.
D= delete from i where inv_amt<10000;

Q2
a) List the names of employees who are also investors.
A= select emp_name from e,i where e.emp_id=i.emp_id;
b)List the information of Investors whose name start
with ‘R’
B= select*from e where emp_name like 'R%';

c) Increase the amount of investors by 10%.


C= update i set inv_amt = inv_amt + (inv_amt * 10/100);

d) Delete the investor information whose amount is


20,000.
D= delete from i where inv_amt=20000;

Q3)
a)List the names of customers who are either
employees, or investors or both.
A= select emp_name from e,i where e.emp_id=i.emp_id
union all select emp_name from e;
b)Delete the employee whose names starts with ‘S’
B= delete from e where emp_name like'S%';

c) List the employees who are living in Mumbai city.


C= select * from e where address = ‘mumbai';

d) Update amount to Rs. 50000 of investors having


amount less than Rs 10,000.
D= update i set inv_amt=50000 where inv_amt<10000;

Q2)
Project (P_No, P_Name,P_Type,Duration)
Employee (E_no, E_Name,Qualification,JoinDate)
Project and Employee: M-M relationship, with
descriptive attributes as start_date (date),
no_of_hours_worked (integer).
Assume appropriate data types for all the attributes.
aproject=project
ebmeployee=employee
e_p=join table
create table aproject(P_No int primary key, P_Name
varchar(20),P_Type text,Duration int);
create table ebmployee(E_no int primary key ,E_Name
varchar(20),Qualification text,JoinDate date);
create table e_p(start_date date,no_of_hours_worked
int,E_no int references ebmployee on delete cascade,P_no int
references aproject on delete cascade);

Q1)
a) Find the employees whose name starts with ‘A’.
= A= select*from ebmployee where e_name like'a%';
A

b) Find the details of employees working on the project


“System”.
B= select*from ebmployee,aproject,e_p where
p_name='system' and e_p.p_no=aproject.p_no and
e_p.e_no=ebmployee.e_no;

c) List the names of the first three employees in


alphabetical order.
C=select * from ebmployee order by e_name asc limit 3;

d) Find the names of the employees whose duration is


more than five years.
D= select*from ebmployee,aproject,e_p where
duration>5 and e_p.p_no=aproject.p_no and
e_p.e_no=ebmployee.e_no;

Q2)
a) Find the names of the employees whose duration is
more than 10 years
A= select*from ebmployee,aproject,e_p where
duration>10 and e_p.p_no=aproject.p_no and
e_p.e_no=ebmployee.e_no;
b) Find the details of employees working on the project
“Robotics”.
B= select*from ebmployee,aproject,e_p where
p_name='Robotis' and e_p.p_no=aproject.p_no and
e_p.e_no=ebmployee.e_no;

c) List the names of the employees in alphabetical order.


C= select * from ebmployee order by e_name asc;

d) Delete the information of employee whose


qualification is B.E.

D= delete from ebmployee where qualification='b.e';

Q3)
a) Find the employee numbers of the employees, who
do not work on project “Robotics”.
A= select*from ebmployee,aproject,e_p where p_name
not in('Robotis') and e_p.p_no=aproject.p_no and
e_p.e_no=ebmployee.e_no;
b) Find the names of the employees whose duration is
more than three years.
B= select*from ebmployee,aproject,e_p where
duration>3 and e_p.p_no=aproject.p_no and
e_p.e_no=ebmployee.e_no;

c) List the names of employees who is worked for more


than 10 hrs on at least one project
C= select*from ebmployee,e_p where
no_of_hours_worked>10 and ebmployee.e_no=e_p.e_no;

d) Delete the details of the employees starting with ‘S’.


D= delete from ebmployee where e_name like's%';

Q1) Practical Questions on PostgresSQL [Marks 10]


Movie (M_Name, release_year, budget)
Actor (A_name ,role, charges,a_address)
Producer (producer_id, Name, P_address)
Each actor has acted in one or more movies. Each
producer has produced many movies and each
movie can be produced by more than one producers.
Each movie has one or more actors acting in
it, in different roles.
Assume appropriate data types for all the attributes.

create table movie(M_Name varchar(40) primary key,release_year


date,budget int,a_name varchar(50references actor on delete
cascade,producer_id int references producer0 on delete cascade);
create table actor(A_name varchar(60) primary key,role text,charges
int,a_address text);
create table producer0(producer_id int,Name varchar(50),P_address
text);
create table ma(M_name varchar(40) references movie on delete
cascade,A_name varchar(60) references actor on delete cascade,role
varchar(20));
create table mp(M_name varchar(40) references movie on delete
cascade,producer_id int references producer0 on delete cascade);

Q1
a) List the names of movies with the highest budget.
A=select m_name from movie where budget=(select
max(budget) from movie);
b) List the names of producers who produce the same
movie as “Tanhaji”.
B= select * from producer0,movie where m_name =
'tanhaji' and
producer0.producer_id=movie.producer_id;

c) List the names of actors who do not live in Pune or


Mumbai city.
C) select a_name from actor where a_address not in
('pune','mumbai');

d) Delete the information of Producers who are living in


Pune city.
D=delete from producer0 where p_address='pune';

Q2)
a) Gives count of movies whose budget is greater than 3
crores.
A=select count(*)from movie where budget > 30000000;

b) List details of actors who have acted in movie


“Tanhaji”.
B=select * from actor,movie where m_name = 'tanhaji'
and actor.a_name=movie.a_name;

c) Delete the details movie starting with ‘a’.


C=delete from movie where m_name like'a%';

d) List the names of movies, produced by more than one


producer.
D=select m_name from mp group by m_name having
count(m_name)>1;

Q3)
a) List the movie name starting with ‘S’.
A=select m_name from movie where m_name like's%';

b) List the names of actors who have acted in the


maximum number of movies.
B=select max(a_name) from movie;

c) Count all the movies names released in the year 2000.


C=select*from movie where extract(year from
release_year)=2000;

d) Display all movies of “Ranveer Singh”


D) select*from movie where a_name=(select a_name from
actor where a_name='raneer_singh');

Branch (B_id, Brname, Brcity)


Customer (C_no, Cname, Caddress, City)
Loan_Application(L_no,L_amt_required,L_amt_approved,L_date)
Branch, Customer, Loan_Application are related with ternary
relationship.
Ternary (B_id, C_no, L_no)
Assume appropriate data types for all the attributes.
create table branch1(b_id int primary key,b_name
varchar(50),b_city text);
create table customer1(c_no int primary key,c_name
varchar(50),c_address text,city text,b_id int references
branch1 on delete cascade);
create table l_application(l_no int primary key,l_amt_req
int,l_amt_approved int,l_date date,b_id int references
branch1 on delete cascade,c_no int references customer1 on
delete cascade);
create table b_c_l(b_id int references branch on delete
cascade,c_no int references customer1 on delete cascade,l_no
int references l_application on delete cascade);

a) List the names of the customers for the “Aundh” branch.


A= select c_name from customer1 where b_id=(select b_id
from branch1 where b_name='Aundh');
b) Find the maximum loan amount approved.
B= select max(l_amt_approved)from l_application;

c) Count the number of loan application received by “M.G.


Road” branch.
C= select count(l_no)from l_application where b_id=(select
b_id from branch1 where b_name='M.G. Road');

d) Increase the approved loan amount by 2%.


D) update l_application set l_amt_approved=l_amt_approved+
(l_amt_approv
ed*2/100);
a) List the names of the customers for the “Shivajinagar”
branch.
A) select c_name from customer1 where b_id=(select b_id
from branch1 where b_name='Shivajinagar');

b) Find out the total loan amount sanctioned by “Deccan”


branch.
B= select sum(l_amt_approved) from l_application where
b_id=(select b_id from branch1 where b_name='Deccan');

c) List the names of customers who live in Pune city.


C= select c_name from customer1 where city='pune';

d) Count the number of loan applications received by “Aundh”


branch
D= select count(l_no)from l_application where b_id=(select
b_id from branch1 where b_name='Aundh');
a) List the details of customers whose name starts with ‘S’.
A= select*from customer1 where c_name like's%';

b) List the names of the customer along with the branch


names who have applied for loan in the month of September.
B=

c) Find the maximum loan amount approved.


C) select max(l_amt_approved)from l_application;

d) List the branch details of “Mumbai” city


D= select*from branch1 where b_city='mumbai';

Consider the following database


Person (pnumber, pname, birthdate, income)
Area (aname,area_type)
An area can have one or more person living in it ,
but a person belongs to exactly one area.
The attribute ‘area_type’ can have values as either
urban or rural.
Assume appropriate data types for all the
attributes.

a) List the names of all people living in ‘Pune’area.


A= select*from person where a_name='pune';
b) Give the count of people whose income is below
Rs.10000 living in urban area.
B= select count(*)from person,area where
income<10000 and area_type='urban' and
area.a_name=person.a_name;

c) List all people in rural area having maximum


income.
C= select*from person,area where income=(select
max(income)from person)and area_type='rural'
and area.a_name=person.a_name;

d) Delete information of all people staying in


‘urban’ area.
D=delete from person where a_name=(select
a_name from area where a_name=’urban’);
a) List all people area wise living in rural area type.
A=select*from area,person where
area_type='rural' and
area.a_name=person.a_name;

b) Find the count of people area wise.


B=select a_name,count(*) from person group by
a_name;

c) Find average income of people living in urban


area.
C=select avg(income)from person,area where
area_type='urban' and
area.a_name=person.a_name;

d) Delete people staying in ‘rural’ area and having


income less than Rs 50000.
D=
a) List the names of all people whose income is
between is Rs10,000 and Rs.20000.
A=select*from person where income between
10000 and 20000;

b) Find the count of people living in Pune area.


B=select count(*)from person where
a_name='pune';

c) List names of people area wise having minimum


income.
C=select a_name,min(income)from person group
by a_name;

d) Update income to Rs. 10000 of people staying in


‘urban’ area and having income less than Rs
5000 .

D=
Consider the following database maintained by a
college about students and competitions.
STUDENT (sreg_no, name , class)
COMPETITION (c_no , name , C_type)
The relationship is as follows:
STUDENT-COMPETITION: M-M with described
attributes rank and year.
Class should be ‘FYBCA’ , ‘SYBCA’ and ‘TYBCA’
Assume appropriate data types for all the
attributes.

a) List the names of all students studying in FYBCA.


A) select * from student1 where class = 'fybca';

b) Find the count of students participated in Poster


competition class wise.
select count(c_name) from student1,competition
where c_name='poster' ;

c) List the names of students scoring 1 st rank in all


different competition.
select s_name from s_c,student1 where rank = 1
and s_c.sreg_no=student1.sreg_no;
d) Delete all students of class FYBCA participated in
Quiz of competition in year 2018.

se

a) List the names of all students participated in


Quiz Competition.
select s_name from student1,competition where
c_name='quiz';

b) List the names of students participated in more


than two competitions.

c) List the names of students of TYBCA scoring 1st


rank in all different competitions in year
2019.
select s_name from s_c,student1,competition
where class='tybca' and rank=1 and year='2019-8-
9' and s_c.sreg_no=student1.sreg_no and
s_c.c_no=competition.c_no;

d) Change rank of student KIRAN JOSHI of class


SYBCA to 2 nd rank participated in Poster
competition .
ca
a) List the name of all competitions held in year
2019.

select c_name from s_c,competition where year =


'2019-8-9' and s_c.c_no = competit
ion.c_no;

b) List the name of students of FYBCA who


participated in Quiz as well as in Poster
Competition.
select s_name from student1,s_c where
class='fybca' and s_c.sreg_no=student1.sreg_no;

c) List the name of students class wise scoring 1st


rank in all different competitions held in year
2020.
select s_name from student1,s_c where rank = 1
and year = '2020-8-9' and
s_c.sreg_no=student1.sreg_no;

d) Change class of student KIRAN JOSHI to FYBCA


who participated in Poster competition.

Employee (eno, ename, designation, sal)


Department (dno, dname, dloc)
There exists a one-to-many relationship between
department and employee. Create the Relations
accordingly, so that the relationship is handled
properly and the relations are in normalized form
(3NF).

create table de(d_no int primary key,d_name


varchar(50),d_loc t
ext);
create table emple(e_no int primary key,e_name
varchar(50),designation text,constraint c_check
check(designation in('HOD','HR','clerk')),salary
numeric);

a) List the details of employee whose designation


is ‘H.O.D’
A=select*from emple where designation='HOD';
b) List the name of employees whose salary is
above 20000
B= select e_name from emple where salary>20000;

c) Count the number of employees in each


department.
C= SELECT d_no, count(*) FROM emple GROUP BY
d_no;

d) Display department wise employee list.


D=select*from emple order by d_no;

a) List the employees and the department details


location in ‘Mumbai’
A=select*from emple,de where
emple.d_no=de.d_no and d_loc='mumbai';

b) List employee details whose designation is ‘HR’


and location in ‘Pune’
B= select*from emple where designation='HR' and
d_no=(select d_no from de where d_loc='pune');

c) Update all employee’s salary increase by 15%


C=update emple set salary = salary + (salary *
15/100);

d) Find the maximum salary of employee from


each department located at ‘Pune’
D=select max(salary)from emple,de where
emple.d_no=de.d_no and d_loc='pune';
a) Find the employee details whose name is starts
with R.
A=select *from emple where e_name like'R%';
b) Find sum of salary of employees department
wise
B=select d_no,sum(salary)from emple group by
d_no;

c) Delete employee details who are working as


designation ‘clerk’ located in ‘Pune’
C= delete from emple where designation='clerk'
and d_no=(select d_no from de where
d_loc='pune');

d) List employees with department details whose


salary is in between 20000 to 30000
D= select*from emple where salary between
20000 and 30000;
.Property (pno, description, area)
Owner (oname, address, phone)
An owner can have one or more properties, but a
property belongs to exactly one owner. Create
the relations accordingly, so that the relationship is
handled properly and the relations is handled
properly and the relations are in normalized form
(3NF).

create table owner1(o_name


varchar(50)primary key,address text,phone
numeric);
create table property(p_no int primary
key,description text,area text, o_name
varchar(50)references owner1 on delete
cascade);

a) List details of property where area is ‘Moshi’


A=select*from property where area='moshi';

b) List area wise owner property details.


B= select * from property order by area;

c) List property details owned by ‘Mr. Kadam’


C= select*from property where
o_name='mr.kadam';

d) Update phone no of ‘Mr. Patil’ to 987842621


D= update owner1 set phone=987842621 where
o_name='mr.patil';
a) List details of property whose description
‘Banglow’
A= select*from property where
description='banglow';

b) List properties details with owner name in


‘Chinchwad’ area.
B=select*from property where area='chinchwad';

c) Alter table owner to add owner Age attribute.


C=alter table owner add age int;
d) Delete properties of ‘Mr.Patil’ located in
‘Shivajinagar’ area.
D=delete from property where o_name='mr.patil'
and area='shivajinagar';
a) List details of property whose owner name is
‘Mr. Khan’.
A= select*from property where o_name='mr.khan';

b) Find areawise property details with owner


name.
B= select * from property order by area;

c) Count owner wise details of property.


C= SELECT o_name, count(*) FROM property
GROUP BY o_name;

d) Update owner ‘Mr. Patil’ property description to


‘3BHK’.
D=update property set description='3BHK' where
o_name='mr.patil';

Student (sno, s_name, s_class, s_addr)


Teacher (tno, t_name, qualification, experience)
Student-Teacher: M-M with descriptive attributes
Subject.

fu3=# create table student2(sno int primary


key,s_name varchar(20),s_class text,s_addr text);
CREATE TABLE
fu3=# create table teacher(tno int primary
key,t_name varchar(80),qualification text,
experience int);
CREATE TABLE
fu3=# create table st(sno int references student2
on delete cascade,tno int references teacher on
delete cascade,subject text);
CREATE TABLE

a) List teacher details who taught subject ‘DBMS’


select * from teacher,st where subject = 'dbms' and
teacher.tno = st.tno;

b) Find student details with teacher name who


taught class ‘F.Y.B.C.A’
select *from student2,teacher,st where
s_class='fybca' and st.sno=student2.sno and
teacher.tno=st.tno;

c) Find the maximum experience details of teacher.


C= select * from teacher where experience=(select
max(experience)from teacher);

d) Update teacher qualification to ‘Ph.D’ of


‘Mr.Kumar’.
D= update teacher set qualification='phd' where
t_name='kumar';
a) List the students details who study in class
‘S.Y.B.C.A’
A=select*from student2 where s_class='sybca';

b) Find subject wise teacher details.

c) Count the total no. of students whose class is


‘T.Y.B.C.A’
c=select s_class,count(s_class) from student2
where s_class='tybca' group by s_class;

d) Delete teacher details whose name is ‘Mr.


Rajesh’
a) List the teacher details whose qualification is
‘MPhil’
A= select*from teacher where qualification='m
phil';

b) List subject wise student details.

c) Alter table student to add attribute ‘Contact No’.


c=alter table student2 add column c_no decimal;

d) List total number of subjects taught by each


teacher.
Salesman (sno, s_name, start_year)
Trip (tno, from_city, to_city, departure_date,
return_date, amount)
Dept (deptno, dept_name)
a) List salesman details whose department is
‘Computer’

b) List department wise salesman details

c) Find salesman details whose trip budget is less


than 30000.

d) Alter table dept to add attribute ‘dept_location’.


a) Find trip details whose salesman ‘Mr.Patil’.

b) List department wise trip details

c) Find salesman with trip details whose expense is


between 50000 to 100000 expenses.

d) Update trip from city ‘Pune’ to ‘Delhi’ of Mr.Patil


a) List salesman details whose department name is
‘Marketing’

b) Find trip details along with salesman whose


experience is maximum.

c) Alter table salesman to add attribute


‘experience’.

d) Find the departments from which the salesman


has done number of trips more than two.

You might also like