You are on page 1of 12

Practice Q & A

(Chapter 8 - 13)
Chapter 8
1 .
Which of the following queries determines which enrolled students have no
grades at all.

SELECT DISTINCT student_id
FROM enrollment e
WHERE NOT EXISTS
(SELECT '*'
FROM r!de
WHERE e"student_id # student_id$

SELECT DISTINCT student_id
FROM r!de
WHERE NOT EXISTS
(SELECT N%LL
FROM student
WHERE "student_id # student_id$

SELECT student_id
FROM r!de
WHERE r!de_t&'e_(ode # 'HW'
)ND NOT EXISTS
(SELECT N%LL
FROM enrollment
WHERE "student_id # student_id$

SELECT student_id
FROM enrollment e
WHERE student_id IN
(SELECT student_id
FROM r!de
WHERE r!de_t&'e_(ode # 'HW'$
2 .
Write the question for the following query:
SELECT (ourse_no* des(ri'tion
FROM (ourse
WHERE (ourse_no IN
(SELECT (ourse_no
FROM se(tion
WHERE lo(!tion # 'L+++'$
OR 'rere,uisite # -.

List the course number and description of courses with the
prerequisite course number 2. !hese courses should also not e"ist
in the #$C!%&' table.

List the course number and description of courses that have a
location of L111 and a prerequisite of course number 2.

List the course number( prerequisite( and course description of
courses with a location of L111 or a prerequisite course number of 2.

List the course number and description of courses with either the
course number 2 as a prerequisite or a location of L111.
)dditional *+) for Chapters 8,1-. Oracle SQL by Example by )lice /ischert. 0rentice 1all 2234
0age 1 of 12
5ersion: 67272183
- .
Write the question for the following query:
SELECT /irst_n!me* l!st_n!me
FROM instru(tor
WHERE 0i' NOT IN
(SELECT 0i'
FROM 0i'(ode$

List the first and last name of the instructors with 9ip codes that do not
e"ist in the :%0C&;$ table. %nstructors with '<LL values in the 9ip
column do not show in the result.

;isplay the instructor=s first and last name. #how only those that have
a 9ip code in the :%0C&;$ table.

List the instructors with 9ip codes that do not e"ist in the :%0C&;$
table.

#elect the instructors with a '<LL value in the :%0C&;$ table.
8 .
!he following #*L statement can be e"pressed differently. Choose the
correct equivalent statement.
SELECT (ourse_no* 'rere,uisite
FROM (ourse
WHERE (ourse_no IN
(SELECT (ourse_no
FROM se(tion
WHERE N1L(se(tion_no* 22$ 3 4$

SELECT DISTINCT ("(ourse_no* 'rere,uisite
FROM (ourse (* se(tion s
WHERE ("(ourse_no # s"se(tion_no
)ND N1L(se(tion_no* 22$ 3 4

%nvalid query.

SELECT DISTINCT ("(ourse_no* 'rere,uisite
FROM (ourse (* se(tion s
WHERE ("(ourse_no # s"(ourse_no
)ND N1L(se(tion_no* 22$ 3 4

SELECT (ourse_no* 'rere,uisite
FROM (ourse
WHERE NOT EXISTS
(SELECT N%LL
FROM se(tion
WHERE N1L(se(tion_no* 22$ 3 4$
Answers for "Chapter 8"
1.
Which of the following queries determines which enrolled students
have no grades at all.
SELECT DISTINCT student_id
FROM enrollment e
WHERE NOT EXISTS
(SELECT '*'
FROM r!de
)dditional *+) for Chapters 8,1-. Oracle SQL by Example by )lice /ischert. 0rentice 1all 2234
0age 2 of 12
5ersion: 67272183
WHERE e"student_id # student_id$
Note that a student enrolled in multiple classes, but having only a single grade
in one class, is also included in this result.
2.
Write the question for the following query:
SELECT (ourse_no* des(ri'tion
FROM (ourse
WHERE (ourse_no IN
(SELECT (ourse_no
FROM se(tion
WHERE lo(!tion # 'L+++'$
OR 'rere,uisite # -.
List the course number and description of courses with either the
course number 20 as a prerequisite or a location of L.
3.
Write the question for the following query:
SELECT /irst_n!me* l!st_n!me
FROM instru(tor
WHERE 0i' NOT IN
(SELECT 0i'
FROM 0i'(ode$
List the first and last name of the instructors with !ip codes that do
not e"ist in the #$%&'() table. $nstructors with N*LL values in the
!ip column do not show in the result.
+o include instructors with N*LL values use the N'+ ),$-+ operator instead.
4.
+he following -.L statement can be e"pressed differently. &hoose the
correct equivalent statement.
SELECT (ourse_no* 'rere,uisite
FROM (ourse
WHERE (ourse_no IN
(SELECT (ourse_no
FROM se(tion
WHERE N1L(se(tion_no* 22$ 3 4$
-)L)&+ ($-+$N&+ c.course/no, prerequisite
FROM (ourse (* se(tion s
WHERE ("(ourse_no # s"(ourse_no
)ND N1L(se(tion_no* 22$ 3 4
Chapter 3
1 .
) ;%#!%'C! must always be used in the top,most #$L$C! statement of a
set operation.

!rue

>als
e
)dditional *+) for Chapters 8,1-. Oracle SQL by Example by )lice /ischert. 0rentice 1all 2234
0age - of 12
5ersion: 67272183
2 .
%t is possible to combine data from two tables that do not have a primary
?ey7foreign ?ey relationship into one result using a set operation.

!rue

>als
e
- .
@ou cannot order the results of a set operation.

>als
e

!rue
8 .
!he <'%&' and <'%&' )LL set operators have the opposite effect of each
other.

>als
e

!rue
6 .
!o obtain a list of last names that students and instructors share( you use
the A%'<# set operator.

>als
e

!rue
Answers for "Chapter 9"
1.
False 0 ($-+$N&+ must always be used in the top1most -)L)&+ statement
of a set operation.
2.
True $t is possible to combine data from two tables that do not have a
primary 2ey3foreign 2ey relationship into one result using a set
operation.
3.
False 4ou cannot order the results of a set operation.
4.
False +he *N$'N and *N$'N 0LL set operators have the opposite effect of
each other.
5.
False +o obtain a list of last names that students and instructors share, you
use the 5$N*- set operator.
Chapter 1
)dditional *+) for Chapters 8,1-. Oracle SQL by Example by )lice /ischert. 0rentice 1all 2234
0age 8 of 12
5ersion: 67272183
1 .
!here are no restrictions with using the &racle outer Boin operator 2C4.

!rue

>als
e
2 .
!he )'#% Boin synta" is more fle"ible than the &racle outer Boin synta".

!rue

>als
e
- .
#elf Boins are only used for tables with recursive relationships.

>als
e

!rue
8 .
&racle supports a full outer Boin using two outer Boin operators 2C4.

>als
e

!rue
6 .
)ll Boins must be based on the equality of values between the Boining tables.

>als
e

!rue
Answers for "Chapter 10"
1.
False +here are no restrictions with using the 'racle outer 6oin operator 789.
2.
True +he 0N-$ 6oin synta" is more fle"ible than the 'racle outer 6oin
synta".
3.
False -elf 6oins are only used for tables with recursive relationships.
4.
False 'racle supports a full outer 6oin using two outer 6oin operators 789.
5.
False 0ll 6oins must be based on the equality of values between the 6oining
tables.
)dditional *+) for Chapters 8,1-. Oracle SQL by Example by )lice /ischert. 0rentice 1all 2234
0age 6 of 12
5ersion: 67272183
Chapter 11
1 .
@ou cannot selectively delete rows from a table.

!rue

>als
e
2 .
When inserting data into a table from another table( the table names and
columns must be the same.

!rue

>als
e
- .
!ransaction control determines when data manipulation becomes
permanent in a database.

!rue

>als
e
8 .
@ou can update only a single column at a time in a table.

!rue

>als
e
6 .
!he !/<'C)!$ command removes all data permanently from a table.

!rue

>als
e
D .
!he !/<'C)!$ command and the !/<'C function can be used
interchangeably.

!rue

>als
e
E .
!he conditional %'#$/! >%/#! command evaluates the W1$' condition
in order. >or all conditions that are true a row is inserted into the
appropriate table.

!rue

>als
e
8 .
) session is an individual connection to the &racle database server.

!rue

>als
e
)dditional *+) for Chapters 8,1-. Oracle SQL by Example by )lice /ischert. 0rentice 1all 2234
0age D of 12
5ersion: 67272183
3 .
;AL statements such as %'#$/!( <0;)!$( ;$L$!$( and A$/F$
obtain a loc? on the row2s4( so other users cannot manipulate it.

!rue

>als
e
1.
&racle=s multi,versioning feature achieves read,consistent query results.

!rue

>als
e
Answers for "Chapter 11"
1.
False 4ou cannot selectively delete rows from a table.
2.
False When inserting data into a table from another table, the table names
and columns must be the same.
3.
True +ransaction control determines when data manipulation becomes
permanent in a database.
4.
False 4ou can update only a single column at a time in a table.
5.
True +he +:*N&0+) command removes all data permanently from a table.
6.
False +he +:*N&0+) command and the +:*N& function can be used
interchangeably.
7.
False +he conditional $N-):+ ;$:-+ command evaluates the W<)N
condition in order. ;or all conditions that are true a row is inserted
into the appropriate table.
Note: 'nly for the first condition that is true, a row is inserted into the table.
-ubsequent conditions are no longer tested
8.
True 0 session is an individual connection to the 'racle database server.
9.
True (5L statements such as $N-):+, *%(0+), ()L)+), and 5):=) obtain
a loc2 on the row7s9, so other users cannot manipulate it.
10
True 'racle>s multi1versioning feature achieves read1consistent query
results.
Chapter 12
)dditional *+) for Chapters 8,1-. Oracle SQL by Example by )lice /ischert. 0rentice 1all 2234
0age E of 12
5ersion: 67272183
1 .
) table can be created with or without data.

>als
e

!rue
2 .
) table cannot be dropped if it has data in it.

>als
e

!rue
- .
Constraints always have a name.

!rue

>als
e
8 .
Constraints must be e"plicitly enabled before they can be used by the
database.

>als
e

!rue
6 .
@ou can add to and drop columns from a table using the )L!$/ !)GL$
command.

>als
e

!rue
D .
@ou can rename a table with the /$')A$ or the )L!$/ !)GL$
command.

!rue

>als
e
E .
) parent table referenced by a child table may not be dropped.

>als
e

!rue
8 .
!he data of a temporary table is visible to all sessions.

!rue

>als
e
3 .
!he '<AG$/ data type is usually the best choice for a primary ?ey.

!rue

>als
e
)dditional *+) for Chapters 8,1-. Oracle SQL by Example by )lice /ischert. 0rentice 1all 2234
0age 8 of 12
5ersion: 67272183
1.
Gy default( the foreign ?ey restricts deletes of any parent row that has a
corresponding child row2s4.

!rue

>als
e
)dditional *+) for Chapters 8,1-. Oracle SQL by Example by )lice /ischert. 0rentice 1all 2234
0age 3 of 12
5ersion: 67272183
Answers for "Chapter 12"
1.
True 0 table can be created with or without data.
2.
False 0 table cannot be dropped if it has data in it.
3.
True &onstraints always have a name
4.
False &onstraints must be e"plicitly enabled before they can be used by the
database.
5.
True 4ou can add to and drop columns from a table using the 0L+): +0?L)
command.
.
6.
True 4ou can rename a table with the :)N05) or the 0L+): +0?L)
command.
7.
True 0 parent table referenced by a child table may not be dropped.
4ou must either remove the foreign 2ey constraint on the child table or drop
the parent table with the 0L+): +0?L) tablename &0-&0() &'N-+:0$N+
option.
8.
False +he data of a temporary table is visible to all sessions.
0 temporary table is either session1specific or transaction1specific. When a user
creates a session1specific temporary table, the same user cannot see the data
in the temporary table from another session. 'nly the session that created the
data.
9.
True +he N*5?): data type is usually the best choice for a primary 2ey.
'ther data types, such as @0:&<0:2 are prone to punctuation, case1
sensitivity, and spelling mista2es, which ma2e it more difficult to distinguish if
two records are identical. +he (0+) or (0+)+$5) data types contain a
timestamp you will need to ta2e under consideration.
10.
True ?y default, the foreign 2ey restricts deletes of any parent row that has
a corresponding child row7s9.
Chapter 1-
1 .
*<$#!%&': !he following is the C/$)!$ !)GL$ statement of a table
named $A0 and the C/$)!$ 5%$W statement of the A@H$A0 view.
;etermine the salary for the new employee #mith based on the %'#$/!
statement issued.
CRE)TE T)5LE em'
)dditional *+) for Chapters 8,1-. Oracle SQL by Example by )lice /ischert. 0rentice 1all 2234
0age 1 of 12
5ersion: 67272183
(em'_id N%M5ER NOT N%LL*
l!st_nm 1)RCH)R-(6.$*
s!l!r& N%M5ER(+.*-$ DEF)%LT . NOT N%LL$
CRE)TE OR RE7L)CE 1IEW m&_em' )S
SELECT em'_id* l!st_nm
FROM em'
INSERT INTO m&_em'
(em'_id* l!st_nm$
1)L%ES
(++.* 'SMITH'$

#mith=s salary is '<LL.

#mith=s salary is 11.

#mith=s salary is .

!he %'#$/! statement fails
2 .
!he following inde" was created on the #!<;$'! table:
CRE)TE INDEX stud_re_dt ON student(reistr!tion_d!te$
;etermine if the query ta?es advantage of the inde".
SELECT student_id
FROM student
WHERE reistr!tion_d!te 3# TR%NC(S8SD)TE9+$

>als
e

!rue
- .
!he following inde" was created.
C/$)!$ %';$I crseHcostHi &' course 2cost4
;etermine which of the following queries ta?es advantage of the inde".

SELECT (ost
FROM (ourse
WHERE (ost 3# ++"-4.:

SELECT (ost* (ourse_no
FROM (ost
WHERE (ost ;3 +-..

SELECT (ost* (ourse_no
FROM (ost
WHERE N1L((ost* .$ # +-..

SELECT (ost* (ourse_no
FROM (ost
WHERE (ost IS N%LL
Answers for "Chapter 13"
1.
.*)-+$'N: +he following is the &:)0+) +0?L) statement of a table
named )5% and the &:)0+) @$)W statement of the 54/)5% view.
(etermine the salary for the new employee -mith based on the
$N-):+ statement issued.
)dditional *+) for Chapters 8,1-. Oracle SQL by Example by )lice /ischert. 0rentice 1all 2234
0age 11 of 12
5ersion: 67272183
CRE)TE T)5LE em'
(em'_id N%M5ER NOT N%LL*
l!st_nm 1)RCH)R-(6.$*
s!l!r& N%M5ER(+.*-$ DEF)%LT . NOT N%LL$
CRE)TE OR RE7L)CE 1IEW m&_em' )S
SELECT em'_id* l!st_nm
FROM em'
INSERT INTO m&_em'
(em'_id* l!st_nm$
1)L%ES
(++.* 'SMITH'$
-mith>s salary is 0.
Note: No value for the salary has been entered, therefore the default
value is inserted into the table.
2.
True
!he following inde" was created on the #!<;$'! table:
C/$)!$ %';$I studHregHdt &' student2registrationHdate4
;etermine if the query ta?es advantage of the inde".
SELECT student_id
FROM student
WHERE reistr!tion_d!te 3# TR%NC(S8SD)TE9+$
3. !he following inde" was created.
CRE)TE INDEX (rse_(ost_i ON (ourse ((ost$
;etermine which of the following queries ta?es advantage of
the inde".
SELECT (ost
FROM (ourse
WHERE (ost 3# ++"-4.:
)dditional *+) for Chapters 8,1-. Oracle SQL by Example by )lice /ischert. 0rentice 1all 2234
0age 12 of 12
5ersion: 67272183

You might also like