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

Week 6

The document consists of a series of questions and answers related to SQL queries and database concepts, including conditions under which view updates are not allowed, the usage of HAVING and GROUP BY clauses, and various SQL query examples. It includes true/false statements and multiple-choice questions with accepted answers and scores. The document serves as a quiz or test format for assessing knowledge of SQL and database management.

Uploaded by

samayrb2024
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)
2 views7 pages

Week 6

The document consists of a series of questions and answers related to SQL queries and database concepts, including conditions under which view updates are not allowed, the usage of HAVING and GROUP BY clauses, and various SQL query examples. It includes true/false statements and multiple-choice questions with accepted answers and scores. The document serves as a quiz or test format for assessing knowledge of SQL and database management.

Uploaded by

samayrb2024
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

10:53 PM&X ll wiEi 17:

1) Under which of the following conditions, the 2 points


update operations on views are NOT allowed?
() if the view definition has an aggregate operator
(ii) if the viewdefinition includes two or more tables
(ii) if the view is defined on a single table without group by,
aggregates and the SELECT clause includes the primary key
of the table

Only (ii)
Only (ii)
Only () and (i)
All (), () and (ii)
Yes, the answer is correct.
Score: 2
Accepted Answers:
Only (i) and (ii)

State whether the following statements are true or false.


2) HAVING clause can be used in a query only if 0.5 points
GROUP BY clause is used

True

OFalse
Yes, the answer is correct.
Score: 0.5
Accepted Answers:
True

3) GROUP BY clause can be used in a query 0.5 points


only if HAVING Clause is used

True

OFalse
No, the answer is incorrect.
Score: 0

Accepted Answers:
False
Accepted
False
Answers: WiFi 17

4) It is
mandatory to
in a query if use an
aggregate function 0.5 points
GROUP BY clause is used
True
False
No, the answer is
Score: 0 incorrect.
Accepted Answers:
False
5) Aggregate
BY clauses functions can be used in GROUP 0.5 points
True

OFalse
No, the answer is
Score: 0 incorrect.
Accepted Answers:
False

6) In which of the
following SQL clauses of a 2 points
main query can a sub-query be made use of ?
() FROM (ii) WHERE (iii)
HAVING
Only (ii)
Only (ii)
Only (i) and (ii)
All ().,() and (ii)
Yes, the answer is correct.
Score: 2
Accepted Answers:
All (), (i) and (ii)

7) Which of the following queries would select 2peints


the courses with at least 10 W' grades in some offeri
the course
10:53 PMA X Vo
WiFi 117 )

7) Which of the following queries would select 2points


the courses with at least 10 'W grades in some offering of
the course ?

SELECT courseld
FROM enrollment
WHERE grade = W
GROUP BY courseld
HAVING Count(rollNo) >= 10
SELECT courseld
FROM enrollment
WHERE grade ="W
GROUP BY COurseld, sem, year
HAVING count(rollNo) >= 10
O
SELECT courseld
FROM enrollment
WHERE grade =W AND Count(rollNo) >= 10
GROUP BY courseld

OSELECT Courseld
FROM enrollment
WHERE grade =W AND count(rollNo) >= 10
GROUP BY courseld,sem, year
Yes, the answer is correct.
Score: 2
Accepted Answers:
SELECT courseld
FROM enrollment
WHERE grade = W
GROUP BY courseld, sem, year
HAVING count(rollNo) >= 10

8) Which of the following queries willretrieve 2 points


students whose name has 'p' as the second letter ?

SELECT rollNo FROM student where name =_p';


SELECT rollNo FROM student where name LIKE_p';
SELECT rollNo FROM student where name LI
p%;
SELECT rollNo FROM student where name IN'_p%;
+ (15)
C% inecOurses.nptel.ac.in

relations R1(A, 2 points


of the
Consider two instances rows 10 and 8,
9) number of
B) and R2 (C,
D) with the
possible number of tuples in
least
respectively. What is the query?
the following
the result of

SELECT *
JOIN R2 ON R1.A = R2.C
RIFULL OUTER
FROM

Oo
18

O8

10
incorrect.
No, the answer is
Score: 0
Accepted Answers:
10

queries. Which of the 2 points


10)Consider the folowing
find the courses with no
following queries is correct to
prerequisites?

() SELECT cOurseld
FROM preRequisite
GROUP BY courseld
HAVING count(preCourseld) =0

(ii) SELECT Courseld


FROM preRequisite a
WHERE NOT EXISTS (
SELECT preCourseld FROM preRequisite b WHERE
a.courseld = b.courseld)

Oonly ()
Only (i)
Both (i) and (ii)
Neither () nor (ii)
10:54 PM&X Vo
WiFi 17

10)Consider the following queries. Which of the 2 points


following queries is correct to find the courses with no
prerequisites?

() SELECT Courseld
FROM preRequisite
GROUP BY courseld
HAVING Count(preCourseld) =0

(ii) SELECT Courseld


FROM preRequisite a
WHERE NOT EXISTS (
SELECT preCourseld FROM preRequisite b WHERE
a.courseld = b.courseld)

Only (i)
Only (i)
Both () and (i)
Neither (i) nor (ii)
Yes,the answer is correct.
Score: 2
Accepted Answers:
Neither (i) nor (ii)

11)Which of the following queries would find the 2 points


id and name of the senior-most hod(s)?

SELECT p1.empld, p1.name


FROM professor p1
WHERE p1.startYear IN(
SELECT min(p.startYear)
FROM professor p, department d
WHERE p.empld =d.hod)
OSELECT p.empld, p.name
FROM professor p, department d
WHERE p.empld = d.hod
WHERE p.startYear IN(
SELECT min(p1.startYear)
FROM professor p1)
10:54 PM X lll Vo
wiEi17

12)Which one of the following queries would find 2 points


the teacher(s) who taught CS1100 the highest number of
times?

CREATE VIEW EmpCount AS


SELECT empld, count(*) AS cnt
FROM teaching
WHERE Courseld ='CS1100
GROUP BY empld

SELECT empld
FROM EmpCount
WHERE Cnt = (SELECT MAX(cnt) from EmpCount)
CREATE VIEW EmpCount AS
SELECT empld, count(*) AS cnt
FROM teaching
WHERE courseld ='CS1100

SELECT empld
FROM EmpCount
WHERE Cnt = (SELECT MAX(cnt) from EmpCount)
CSELECT empld, max(count()) AS cnt
FROM teaching
WHERE courseld= 'CS1100'
GROUP BY empld
SELECT empld
FROM teaching
WHERE courseld 'CS1100
GROUP BY empld
HAVING COUNT(*) =(
SELECT max(count(*) FROM teaching WHERE
courseld='CS1100')
Yes, the answer is correct.
Score: 2
Accepted Answers:
CREATE VIEW EmpCount AS
SELECT empld, count() AS cnt
FROM teaching
WHERE courseld= 'CS1100'
rDAl iD DVamnld
ACcepted Answers:
CREATE VIEW EmpCount AS
BELECT empld, count() AS cnt
FROM teaching
WHERE Courseld = 'CS1100'
GROUP BY empld

SELECT empld
FROM EmpCount
WHERE cnt =(SELECT MAX(cnt) from EmpCount)

13)Consider the following sets about different 2 points


approaches to programmatic access of databases and the
oroperties that may apply to these approaches.
41:Embedded SQL approach;2: API based approach; 3:
Database language approach)
{p: Only one
connection to a DB server can be active at any
time q: Open Database
Connectivity
Programmers need to learn a new
(ODBC); r: Cursors; s:
connections DB servers can be language;t: Multiple
to
active at any time}
Identify the correct matching
between the sets:
1-p, 2-t, 3-q
1-t; 2--q; 3--s
1-s, 2-r,3-p
1-p, 2-t;3--s
Yes, the answer is
Score: 2. correct.
Accepted Answers:
1-p; 2-t; 3-s

You might also like