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

Week 2 Solution

The document contains a 9 question assignment on database management systems worth a total of 20 marks. The questions cover topics like different types of joins, foreign key constraints, deleting and truncating tables, aggregation, and updating records. Each question includes multiple choice or multiple selection answers to choose from, along with an explanation of the correct answer.

Uploaded by

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

Week 2 Solution

The document contains a 9 question assignment on database management systems worth a total of 20 marks. The questions cover topics like different types of joins, foreign key constraints, deleting and truncating tables, aggregation, and updating records. Each question includes multiple choice or multiple selection answers to choose from, along with an explanation of the correct answer.

Uploaded by

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

Database Management System: Assignment 2

Total Marks : 20

July 9, 2023

Question 1
Consider two relations StyleName and PrintStyle as follows:

StyleName PrintStyle
Element Style Element Color
Flower Floral Square Blue
Square Block Lines Multi

An operation Θ between StyleName and PrintStyle will generate the following output:

Style Print
Element Style Color
Flower Floral NULL
Square Block Blue
NULL Lines Multi

Identify the operation Θ. Marks: 2 MCQ

a) natural join

b) natural left outer join

c) natural right outer join

d) natural full outer join

Answer: d)
Explanation: For natural join, none of the tuples 1 and 3 would not be present in the output.
For left or right outer join, one of the tuples 1 and 3 would not be present in the output. Only
in full outer join all 3 tuples will be present in the output.
Hence, option d) is correct.

1
Question 2
Consider the following CREATE statements: Marks: 2 MCQ

CREATE TABLE faculty(


faculty_id INT PRIMARY KEY,
faculty_name VARCHAR(50) NOT NULL,
);

CREATE TABLE course(


course_id INT PRIMARY KEY,
faculty_id INT NOT NULL,
course_fees INT,
FOREIGN KEY (faculty_id)
REFERENCES faculty (faculty_id)
ON DELETE RESTRICT
);

Identify the correct statement(s) from the following options.

a) If a faculty id value is deleted from the faculty table, the corresponding records in the
course table that use this faculty id will not be deleted.

b) If a faculty id value is deleted from the faculty table, the corresponding records in the
course table that use this faculty id will also be deleted.

c) If a faculty id value is deleted from the faculty table, the foreign key constraint will become
invalid.

d) If a faculty id value is deleted from the faculty table, the corresponding records in the
course table that use this faculty id will be deleted and the foreign key constraint will
become invalid.

Answer: a)
Explanation: ON DELETE RESTRICT clause deletes the corresponding records in the parent
table only. Hence, option (a) is correct.

2
Question 3
Consider the following schema:

• loan(loan number, branch name, amount)

Identify the correct option(s) in the following to delete all rows from loan table.
Marks: 2 MSQ

a) DELETE * FROM loan;

b) DELETE FROM loan;

c) DROP TABLE loan;

d) TRUNCATE TABLE loan;

Answer: b), d)

Explanation: To delete all rows from a table we can use either DELETE or TRUNCATE command
and the syntax for these commands are:

DELETE FROM table name


[WHERE conditions];

Here, the condition is optional and another one is:

TRUNCATE TABLE table name;

So, options b) and d) are correct.

3
Question 4
Consider the following instance of the relation
BIDDINGTAB(PRODUCTID, HIGHESTBID, LOWESTBID, WINNER, BIDDERS)

PRODUCTID HIGHESTBID LOWESTBID WINNER BIDDERS


1EXP03 50000 2000 Chris L. 10
13HP05 45000 10000 Amara D. 50
S0W125 80000 1000 Lewis F.H 25
S0W128 80000 300 Lewis F.H 12
1EXP02 25000 100 John L. 7
Howe many tuples will be returned by the following SQL Query?
SELECT WINNER
FROM BIDDINGTAB
WHERE HIGHESTBID<=(
SELECT AVG(HIGHESTBID)
FROM BIDDINGTAB)
AND WINNER LIKE ‘ L.’ Marks: 2 MCQ

a) 0

b) 2

c) 3

d) 5

Answer: a)
Explanation: The average of HIGHESTBID from the given instance is 56000. Thus, SELECT
WINNER FROM BIDDINGTAB WHERE HIGHESTBID<=( SELECT AVG(HIGHESTBID) FROM BIDDINGTAB)
WINNER
Chris L.
results in 3 tuples . However, none of the WINNER’s name is ‘ L.’. Thus the in-
Amara D.
John L.
tersection of the two conditions in the query produces 0 tuples. Hence, option (a) is correct.

4
Question 5
Consider the following instance of the relation
BIDDINGTAB(PRODUCTID, HIGHESTBID, LOWESTBID, WINNER, BIDDERS)

PRODUCTID HIGHESTBID LOWESTBID WINNER BIDDERS


1EXP03 50000 2000 Chris L. 10
13HP05 45000 10000 Amara D. 50
S0W125 80000 1000 Lewis F.H 25
S0W128 80000 300 Lewis F.H 12
1EXP02 25000 100 John L. 7
If the following SQL Query is executed, which of the following options will be true?
SELECT MAX(BIDDERS), WINNER
FROM BIDDINGTAB
GROUP BY HIGHESTBID, WINNER
ORDER BY WINNER DESC; Marks: 2 MCQ

a) <50, Amara D.> will be the first tuple in the output.

b) <25, Lewis F.H> will be the first tuple in the output.

c) <12, Lewis F.H> will be the first tuple in the output.

d) <12, Lewis F.H> will be the last tuple in the output.

Answer: b)
Explanation: Based on the given SQL Query, the following will be the output
MAX(BIDDERS) WINNER
25 Lewis F.H
7 John L.
10 Chris L.
50 Amara D.
Hence, option (b) is the correct option.

5
Question 6
Consider the following instance of the relational schema PAYSCALE(POSITION, BASE SALARY,
EXPERIENCE)
POSITION BASE SALARY EXPERIENCE
MANAGER 75000 1
MANAGER 90000 5
CLERK 35000 5
DEVELOPER 50000 3
DEVELOPER 70000 5
SCIENTIST 90000 2
Which POSITION will NOT be present in the output generated by the following SQL Query?
SELECT DISTINCT(POSITION)
FROM PAYSCALE
WHERE BASE SALARY<SOME(
SELECT AVG(BASE SALARY)
FROM PAYSCALE
GROUP BY EXPERIENCE); Marks: 2 MCQ

a) CLERK

b) DEVELOPER

c) SCIENTIST

d) MANAGER

Answer: c)
Explanation: As per the syntax and semantics of SQL Queries. Refer to Week 2, slide 8.11.
Hence, option (c) is correct.

6
Question 7
A role Manager has the privilege to perform select, insert, update and delete operations on all
tables of database. A new role Software Engineer is created and the following statement is
executed.

grant Manager to Software Engineer;

Which rights will Software Engineer inherit? Marks: 2 MCQ

a) Only select

b) Only select and delete.

c) Only select, and update but not delete.

d) All rights - select, delete, update.

Answer: d)
Explanation: All the privileges of the role of Manager transferred to Software Engineer.

7
Question 8
Consider the following instance of MountainDetails(MountainName,Altitude,StateName)
relation. Marks: 2 MCQ
MountainDetails
MountainName Altitude StateName
Kangchenjunga 8586 Sikkim
Nanda Devi 7816 Uttarakhand
Trisul 7120 Uttarakhand
Kamet 7756 Uttarakhand
Sandakfu 3636 West Bengal
Saltoro Kangri 7742 Jammu and Kashmir
Reo Purgyill 7742 Himachal Pradesh

Identify the correct statement(s) to get the following output:

MountainDetails
MountainName Altitude StateName
Kangchenjunga 8586 Sikkim
Nanda Devi 7816 Uttarakhand
Trisul 7120 Uttarakhand
Kamet 7756 Uttarakhand

a) SELECT * FROM MountainDetails


WHERE StateName IN(‘Sikkim’,‘Uttarakhand’);

b) SELECT * FROM MountainDetails


WHERE StateName TO(‘Sikkim’,‘Uttarakhand’);

c) SELECT * FROM MountainDetails


WHERE StateName AS(‘Sikkim’,‘Uttarakhand’);

d) SELECT * FROM MountainDetails


WHERE StateName TO(‘Sikkim’,‘Uttarakhand’) OR Altitude>=7120;

Answer: a)
Explanation: Output table containing tuples whose StateName is either Sikkim or Uttarak-
hand. The IN operator allows to specify multiple values in a WHERE clause
Hence, option a) is correct.

8
Question 9
Consider the given relational schema: MountainDetails(MountainName, Altitude, StateName)
Marks: 2 MCQ

Identify the correct SQL command that updates the Altitude by 5% for all records whose
StateName ends with character ‘d’.

a) UPDATE MountainDetails
OF Altitude=Altitude*1.05
WHERE StateName LIKE ‘%d’;

b) UPDATE MountainDetails
SET Altitude=Altitude*1.05
WHERE StateName LIKE ‘%d’;

c) UPDATE MountainDetails
AS Altitude=Altitude*1.05
FROM MountainDetails
WHERE StateName LIKE ‘%d’;

d) UPDATE MountainDetails
SET Altitude=Altitude*1.05
WHERE StateName LIKE ‘%d%’;

Answer: b)
Explanation: As per SQL syntax, LIKE ‘%d’ matches StateName having last character as
‘d’. The percent sign represents zero, one, or multiple characters.
The underscore sign ( ) represents one, single character.
General syntax for upadte statement is:

UPDATE Tablename
SET column1 = value1, column2 = value2, ...
WHERE condition;

Hence, option b) is correct.

9
Question 10
Consider the given relational schema: MountainDetails(MountainName, Altitude, StateName)
Marks: 2 MCQ

Identify the correct statement to find the MountainName, Altitude whose Altitude is greater
than or equal to the average Altitude of all Mountains or Altitude in between 6500 and 8000.

a) SELECT MountainName, Altitude


FROM MountainDetails
WHERE Altitude>=(SELECT AVG(Altitude) from MountainDetails)
OR Altitude LIKE(6500, 8000);

b) SELECT MountainName, Altitude


FROM MountainDetails
WHERE Altitude>=(SELECT AVG(Altitude) from MountainDetails)
OR Altitude IN(6500, 8000);

c) SELECT MountainName, Altitude


FROM MountainDetails
WHERE Altitude>=(SELECT AVG(Altitude) from MountainDetails)
OR Altitude BETWEEN 6500 AND 8000;

d) SELECT MountainName, Altitude


FROM MountainDetails
WHERE Altitude>=(SELECT AVG(Altitude) from MountainDetails)
OR Altitude AS(6500, 8000);

Answer: c)
Explanation: The BETWEEN operator selects values within a given range. The values can be
numbers, text, or dates and begin and end values are included. AVG(Altitude) is used to
calculate average altitude of all mountains
Hence, option c) is correct.

10

You might also like