You are on page 1of 6

MPSTME, NMIMS Shirpur

Department of Computer Engineering


MBATECH/BTECH CE, CS 2nd Year
Subject: DBMS
Assignment-2
Subject: Database Management System Date of Submission: 11/03/2024
Note: Submit all questions.
1. Consider the following database with primary key underlined
S(Sno,sname,city,status)
P(Pno,pname,color,weight)
SP(Sno,Pno,quantity)
Write SQL expression for following queries:
a. Get the name of suppliers from each city in ascending order of their sname.
SELECT sname, city
FROM S
ORDER BY city ASC, sname ASC;

b. Get supplier number who supply quantity greater than average quantity of
product no 20.
SELECT DISTINCT Sno
FROM SP
WHERE quantity > (SELECT AVG(quantity) FROM SP WHERE Pno = '20');

c. Increase the quantity of parts “A “by 10%.


UPDATE SP
SET quantity = quantity * 1.1
WHERE Pno = 'A';

d. Get different colour of parts supplies by S1.


SELECT DISTINCT color
FROM P
WHERE Pno IN (SELECT Pno FROM SP WHERE Sno = 'S1');

e. Get the name of all the suppliers whose city name starts with ‘A’ and ends with
‘B’
SELECT sname
FROM S
WHERE city LIKE 'A%B';
2. Consider a relation scheme R = (A, B, C, D, E, H) on which the following
functional dependencies hold: {A–>B, BC–> D, E–>C, D–>A}. What are the
candidate keys of R?

So candidate keys are AEH, BEH & DEH .


3. Explain 2NF and 3 NF.
Consider the following functional dependencies in a database.
Date_of_Birth->Age
Age->Eligibility
Name->Roll_number
Roll_number->Name
Course_number->Course_name
Course_number->Instructor
(Roll_number,Course_number)->Grade

1. Second Normal Form (2NF):
- A relation is in 2NF if it is in 1NF (First Normal Form) and every non-prime
attribute is fully functionally dependent on the primary key.
- In simpler terms, 2NF ensures that there are no partial dependencies in a relation.
- Partial dependency occurs when a non-prime attribute is functionally dependent on
only a part of the primary key, not the whole key.
- To achieve 2NF, you often need to break the relation into smaller relations to
eliminate partial dependencies.

2. Third Normal Form (3NF):


- A relation is in 3NF if it is in 2NF and every non-prime attribute is non-
transitively dependent on the primary key.
- In other words, 3NF removes transitive dependencies from the relation.
- Transitive dependency occurs when a non-prime attribute is functionally
dependent on another non-prime attribute, rather than directly on the primary key.
- To achieve 3NF, you may need to further decompose the relation to eliminate
transitive dependencies.
These functional dependencies describe relationships between attributes in a database:

1. Date_of_Birth -> Age : This means that given someone's date of birth, you can
determine their age. It's a straightforward dependency.

2. Age -> Eligibility : This suggests that eligibility for something (probably a
particular program or service) is determined by age.

3. Name -> Roll_number : This means that given a person's name, you can determine
their roll number. This is common in academic contexts.

4. Roll_number -> Name : This is the inverse of the previous dependency, meaning
that given a roll number, you can determine the corresponding name.

5. Course_number -> Course_name : Given a course number, you can determine the
course's name.

6. Course_number -> Instructor : Similarly, given a course number, you can


determine who the instructor is for that course.

7. (Roll_number, Course_number) -> Grade : This composite dependency suggests


that given a combination of a roll number and a course number, you can determine the
grade that the student received in that course. This implies that there might be a table
recording grades with a composite key consisting of roll number and course number.

4. Let ri(z) and wi(z) denote read and write operations respectively on a data item z by a
transaction Ti. Consider the following two schedules.
S1 : r1(x) r1(y) r2(x) r2(y) w2(y) w1(x)
S2 : r1(x) r2(x) r2(y) w2(y) r1(y) w1(x)

In which of the given shedules is conflict serializable or not conflict serializable.

5. Solve the queries based on data given below:

create table employee(empid int primary key,empname varchar(100), department


varchar(50),contactno bigint, emaildid varchar(100), empheadid int)
create table empdept(deptid varchar(50) primary key,deptname varchar(100), dept_off
varchar(100), depthead int foreign key references employee(empid))

create table empsalary(empid int foreign key references employee(empid), salary


bigint, ispermanent varchar(3))

create table project(projectid varchar(50) primary key, duration int)


create table country(cid varchar(50) primary key, cname varchar(100))

create table clienttable(clientid varchar(50) primary key, clientname varchar(100), cid


varchar(50) references country(cid))

create table empproject(empid int foreign key references employee(empid), projectid


varchar(50) foreign key references project(projectid), clientid varchar(50) foreign key
references clienttable(clientid),startyear int, endyear int)
i. Select the details of the employee who work either for department E-104 or E-102.
ii. What is total salary that is paid to permanent employees?
iii. How many project started in year 2010.
iv. Select the name of the employee who is working under Abhishek.
v. Select the name and email of the Dept Head who is not permanent.
vi. Select the details of all employee working in development department.

You might also like