You are on page 1of 6

Lesson 3: Manipulating Data

Multiple Choice
1. What command do you use to perform a query in SQL?
a USE
! SELECT
c QUERY
d CHOSE
"ns#er: !
Difficulty: !
Section $eference: %sing Queries to Select Data
&'planation: (he SQL command for retrie)ing any data from a data!ase is SELECT. Much li*e
any other SQL command+ it #ill read similar to an &nglish statement.
,. What #ildcard character retrie)es all records #ith the SELECT command?
a *
! %
c $
d ?
"ns#er: a
Difficulty: &asy
Section $eference: %sing Queries to Select Data
&'planation: -f you #ant to choose all column names from #ithin a ta!le+ use an asteris* .* in
place of #here the column name #ould !e identified.
3. What #ould you use to com!ine t#o parameters in a query in SQL?
a PLUS
! BOTH
c COMBINE
d AND
"ns#er: d
Difficulty: Medium
Section $eference: /om!ining /onditions
&'planation: -f you need more from a query than simply one set of parameters+ you can use an
AND clause to com!ine se)eral conditions in one query statement to satisfy your requirements.
0or e'ample+ if you #ant to find the employees #ho #or* in the Shipping department !ut also
#ant to find out #hich of those employees are female+ you #ould use this query:
SELECT first_na!" #ast_na!
$ROM !%#&'!!s
(HERE )!%art!nt * +s,i%%in-+ AND -!n)!r * +$+
1. What clause #ould you use #ith the SELECT command that #ould pull records !ased on a
range?
a COMBO
! BET(EEN
c OR
d COMBINE
"ns#er: !
Difficulty: &asy
Section $eference: %sing the 2&(W&&3 /lause
&'planation: (o help resol)e the a#*#ardness in using the AND clause in a query statement+
replace it #ith a BET(EEN clause instead. (his allo#s you to specify the range to !e used in a
4!et#een ' and y5 query format for a much cleaner statement.
6. What *ey#ord used #ith the SELECT statement is used to not output specified records?
a OR
! DISALLO(
c DISRE.ARD
d NOT
"ns#er: d
Difficulty: &asy
Section $eference: %sing the 37( /lause
&'planation: -n some instances+ you might find it simpler to #rite your query to search data in
terms of #hat you don8t #ant in your output. (ransact9SQL pro)ides you #ith a NOT *ey#ord for
use in such situations.
:. What #ould you use to com!ine columns from t#o different ta!les?
a AND
! BET(EEN
c /OIN
d COMBINE
"ns#er: c
Difficulty: Medium
Section $eference: %sing the %3-73 /lause
&'planation: (he ;7-3 clause allo#s you to com!ine related data from multiple ta!le sources.
;7-3 statements are similar in application that !oth &</&=( and -3(&$S&/( do in that they
return )alues from t#o separate ta!le sources. 2ased on this *no#ledge+ #e can mo)e for#ard
#ith learning #hat data can !e e'tracted !y using ;7-3 statements.
>. Which clause used #ith the SELECT command #ill return )alues that you #ant to e'clude from
the normal parameters?
a E0CEPT
! INTERSECT
c SEARCH
d E0CLUDE
"ns#er: a
Difficulty: &asy
Section $eference: %sing the &</&=( and -3(&$S&/( /lauses
&'planation: (he E0CEPT clause returns any of those distinct )alues from the left query that are
not also found on the right query.
?. What clause is used to com!ine related data from multiple ta!le sources?
a COMBINE
! AND
c /OIN
d PLUS
"ns#er: c
Difficulty: @ard
Section $eference: %sing the ;7-3 /lause
&'planation: (he /OIN clause allo#s you to com!ine related data from multiple ta!le sources.
/OIN statements are similar to !oth E0CEPT and INTERSECT in that they return )alues from t#o
separate ta!le sources.
A. What statement #ould you use to add data to a ta!le?
a ADD
! INSERT
c /OIN
d PRESENT
"ns#er: !
Difficulty: Medium
Section $eference: %sing Queries to -nsert Data
&'planation: -f you are loo*ing to insert small quantities of dataBfor instance+ adding a fe# ne#
ro#s into your data!aseByou can accomplish this !y using the graphical interface tool or !y
using the INSERT statement.
1C. What statement #ould you use to change data in a ta!le?
a CHAN.E
! MODI$Y
c INSERT
d UPDATE
"ns#er: d
Difficulty: Medium
Section $eference: %sing the %=D"(& Statement
&'planation: (he UPDATE clause allo#s you to modify the data stored in ta!les !y using data
attri!utes such as the follo#ing:
UPDATE 1ta2#!_na!3
SET 1attri24t!3 * 15a#4!3
(HERE 16&n)iti&ns3
11. What statement is used to delete one or more ro#s in a ta!le?
a DELETE
! REMO7E
c TRUNCATE
d CHAN.E
"ns#er: a
Difficulty: &asy
Section $eference: Deleting Data
&'planation: (he DELETE statement is used to perform the e'act function it states: remo)e ro#s
from a ta!le or a )ie#. Dou can use DELETE in se)eral #ays+ depending on the amount of data
you need to ha)e remo)ed. (he simplest method is to identify and delete indi)idual ro#s from
#ithin the data!ase using the DELETE command synta'.
1,. What statement is used to delete a ta!le from a data!ase?
a DELETE
! DROP
c REMO7E
d TRUNCATE
"ns#er: !
Difficulty: Medium
Section $eference: Deleting a (a!le #ith D$7= ("2L&
&'planation: Suppose that you #ant to delete an entire ta!le !ecause it8s o!solete. (he remo)al
of an entire ta!le loo*s li*e this:
DROP TABLE 1ta2#!_na!3
13. @o# can you pre)ent the accidental loss of an entire ta!le?
a %se the DELETE TRANS command.
! %se the LOOPBAC8 command.
c %se the SA$EDELETE command.
d %se referential integrity.
"ns#er: d
Difficulty: @ard
Section $eference: %sing $eferential -ntegrity
&'planation: " failo)er measure that you can ta*e regarding data!ase ta!les is using referential
integrity practice methods. 7ne of the most common mista*es of data!ase manipulating is the
accidental loss of entire ta!les. (he !est #ay to a)oid this type of situation in the first place is to
ensure that your data!ase is using referential integrity. $eferential integrity does not allo#
deletion of ta!les+ unless they are actually at the end of the relationship.
11. What do you perform #hen you #ant to recall specific records from a data!ase?
a recall
! )irtual e'traction
c reach
d query
"ns#er: d
Difficulty: &asy
Section $eference: %sing Queries to Select Data
&'planation: Dou use the SELECT statement to retrie)e or e'tract data from one ta!le+ retrie)e or
e'tract data !y using Eoins+ and com!ine results !y using UNION and INTERSECT. When you
retrie)e or e'tract data from a ta!le+ you are performing a query.
16. What command #ould you use to delete a ta!le #hile lea)ing the ta!le structure in place for
future use?
a DELETE TABLE
! TRUNCATE TABLE
c REMO7E TABLE
d STOP TABLE
"ns#er: !
Difficulty: Medium
Section $eference: (runcating a (a!le #ith ($%3/"(& ("2L&
&'planation: (he TRUNCATE TABLE statement remo)es only the data from #ithin the ta!le !ut
lea)es the ta!le structure in place for future use.
Short Answer
1:. What statement #ould you use to pull 0irstF3ame+ LastF3ame+ and -DF3um!er from the
%sers ta!le?
"ns#er: SELECT $irst_Na!" Last_Na!" ID_N42!r
$ROM Us!rs
Difficulty: @ard
Section $eference: %sing Queries to Select Data
&'planation: (he SQL command for retrie)ing any data from a data!ase is SELECT. Much li*e
any other SQL command+ it #ill read similar to an &nglish statement. /omposing a SELECT
statement is similar to filling in the !lan*s+ such as the follo#ing:
SELECT i)" na! 996&#4ns
$ROM s's&2:!6ts 99 ta2#!s
(HERE t'%! * ;:&n!s; 996&n)iti&ns '&4 <ant t& %r&)46! r!s4#ts fr&
(his is a simple statement+ !ut it pro)ides the !asic understanding of #hat the SELECT statement
does and al#ays follo#s the same pattern each time you issue a SELECT statement to the
data!ase.
1>. What statement #ould you use to pull all records in #hich the State is /" from the %sers
ta!le?
"ns#er: SELECT *
$ROM Us!rs
(HERE Stat! * +CA+
Difficulty: @ard
Section $eference: %sing Queries to Select Data
&'planation: Suppose that you #ant to pro)ide your !oss #ith a list of employees #hose salary
range is a!o)e G6CH. Dou are interested only in retrie)ing those employees #ho fit your !oss8s
criteria. @ere8s ho# you #ould do that in SQL:
SELECT first_na!" #ast_na!" sa#ar'
$ROM !%#&'!!s
(HERE sa#ar' 3* =>">>>
1?. What statement #ould you use to pull 0irstF3ame and LastF3ame from the %sers ta!le in
#hich Iender is 0 and State is /"?
"ns#er: SELECT $irst_Na!" Last_Na!
$ROM Us!rs
(HERE .!n)!r * +$+ AND Stat! * +CA+
Difficulty: @ard
Section $eference: /om!ining /onditions
&'planation: Dou can com!ine se)eral conditions in one query statement to satisfy your
requirements.
1A. What statement #ould you use to list the 0irstF3ame and LastF3ame from the %sers ta!le
#hich Department is not -(?
"ns#er: SELECT $irst_Na!" Last_Na!
$ROM Us!rs
(HERE NOT D!%art!nt * +IT+
Difficulty: @ard
Section $eference: %sing the 37( /lause
&'planation: -n some instances+ it is simpler to #rite your query to search data in terms of #hat
you don8t #ant in your output. (ransact9SQL pro)ides you #ith a NOT *ey#ord for use in such
situations.
,C. What statement #ould you use to delete the &quipment ta!le?
"ns#er: DROP TABLE E?4i%!nt
Difficulty: @ard
Section $eference: Deleting a (a!le #ith DROP TABLE
&'planation: 3o#+ may!e you Eust #ant to delete the entire ta!le? (he remo)al of an entire ta!le
loo*s li*e this:
DROP TABLE 1ta2#!_na!3

You might also like