Upload
rodrigo-nunez
View
217
Download
0
Embed Size (px)
Citation preview
8/10/2019 98 364 Test Bank Lesson03
1/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 SELECTcommand?a *
! %
c $
d ?
"ns#er: aDifficulty: &asySection $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: dDifficulty: MediumSection $eference: /om!ining /onditions&'planation: -f you need more from a query than simply one set of parameters+ you can use an
ANDclause 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,iin-+ AND -!n)!r ++
8/10/2019 98 364 Test Bank Lesson03
2/6
. What clause #ould you use #ith the SELECTcommand that #ould pull records !ased on a
range?a COMBO
! BET(EEN
c OR
d COMBINE
"ns#er: !Difficulty: &asySection $eference: %sing the 2&(W&& /lause&'planation: (o help resol)e the a#*#ardness in using the ANDclause in a query statement+
replace it #ith a BET(EENclause 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 SELECTstatement is used to notoutput specified records?
a OR
! DISALLO(c DISRE.ARD
d NOT
"ns#er: dDifficulty: &asySection $eference: %sing the 7( /lause&'planation: -n some instances+ you might find it simpler to #rite your query to search data interms 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: cDifficulty: MediumSection $eference: %sing the %-7 /lause&'planation: (he ;7- clause allo#s you to com!ine related data from multiple ta!le sources.;7- statements are similar in application that !oth &
8/10/2019 98 364 Test Bank Lesson03
3/6
d E0CLUDE
"ns#er: aDifficulty: &asySection $eference: %sing the &
8/10/2019 98 364 Test Bank Lesson03
4/6
UPDATE 1ta2#!_na!3SET 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
! REMO7Ec TRUNCATE
d CHAN.E
"ns#er: aDifficulty: &asySection $eference: Deleting Data&'planation: (he DELETEstatement is used to perform the e'act function it states: remo)e ro#s
from a ta!le or a )ie#. ou can use DELETEin 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 DELETEcommand 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: MediumSection $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 TRANScommand.
! %se the LOOPBAC8command.
c %se the SAEDELETEcommand.
d %se referential integrity.
"ns#er: d
Difficulty: @ardSection $eference: %sing $eferential -ntegrity&'planation: " failo)er measure that you can ta*e regarding data!ase ta!les is using referentialintegrity practice methods. 7ne of the most common mista*es of data!ase manipulating is theaccidental loss of entire ta!les. (he !est #ay to a)oid this type of situation in the first place is toensure 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.
8/10/2019 98 364 Test Bank Lesson03
5/6
1. What do you perform #hen you #ant to recall specific records from a data!ase?a recall! )irtual e'tractionc reachd query
"ns#er: dDifficulty: &asySection $eference: %sing Queries to Select Data&'planation: ou use the SELECTstatement 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 UNIONand 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 forfuture use?a DELETE TABLE
! TRUNCATE TABLEc REMO7E TABLE
d STOP TABLE
"ns#er: !Difficulty: MediumSection $eference: (runcating a (a!le #ith ($%/"(& ("2L&&'planation: (he TRUNCATE TABLEstatement 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 0irstFame+ LastFame+ and -DFum!er from the%sers ta!le?
"ns#er: SELECT irst_Na!" Last_Na!" ID_N42!rROM Us!rs
Difficulty: @ardSection $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! 996nsROM s's&2:!6ts 99 ta2#!s(HERE t'! ;:&n!s; 996&n)iti&ns '&4
8/10/2019 98 364 Test Bank Lesson03
6/6
1>. What statement #ould you use to pull all records in #hich the State is /" from the %sersta!le?
"ns#er: SELECT *ROM Us!rs(HERE Stat! +CA+
Difficulty: @ardSection $eference: %sing Queries to Select Data&'planation: Suppose that you #ant to pro)ide your !oss #ith a list of employees #hose salaryrange is a!o)e G6CH. ou are interested only in retrie)ing those employees #ho fit your !oss8scriteria. @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 0irstFame and LastFame 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: @ardSection $eference: /om!ining /onditions&'planation: ou can com!ine se)eral conditions in one query statement to satisfy yourrequirements.
1A. What statement #ould you use to list the 0irstFame and LastFame 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: @ardSection $eference: %sing the 7( /lause&'planation: -n some instances+ it is simpler to #rite your query to search data in terms of #hatyou 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 E4i!nt
Difficulty: @ardSection $eference: Deleting a (a!le #ith DROP TABLE
&'planation: o#+ may!e you Eust #ant to delete the entire ta!le? (he remo)al of an entire ta!leloo*s li*e this:
DROP TABLE 1ta2#!_na!3