Sei sulla pagina 1di 83

1. You have been asked to store tme vaues that are accurate to the second.

Whch of
the foowng data types do you use?
a. Datetme
b. unquedentfer
c. smadatetme
d. smant
e. bt
Answer: datetme
Expanaton: datetme - stores date and tme wth seconds whe smadatetme -
stores date and tme wth mnutes
2. Whch one of the foowng T-SOL statements do you use to create an HTTP endpont?
a. SET ENDPOINT
b. CREATE ENDPOINT
c. NEW END_POINT
d. CREATE HTTPENDPOINT
e. SET HTTP_ENDPOINT
Ans: CREATE ENDPOINT
3. Whch one of the foowng tabe names s a temporary tabe that s vsbe ony on
the connecton on whch t was created?
a. ##myTabe
b. _myTabe
c. #myTabe
d. @@myTabe
e. @myTabe
Answer: #myTabe
Expanaton:
#myTabe- oca temporary vsbe ony n one connecton that s created.
##myTabe- goba temporary tabe vsbe to a connecton.
@myTabe-temporary tabe that aways stores n memory
The underscore (_), at sgn (@), or number sgn (#).
Certan symbos at the begnnng of an dentfer have speca meanng n SOL Server.
A reguar dentfer that starts wth the @ sgn aways denotes a oca varabe or
parameter and cannot be used as the name of any other type of ob|ect.
An dentfer that starts wth a # denotes a temporary tabe or procedure.
An dentfer that starts wth doube number sgns (##) denotes a goba temporary
ob|ect.
Athough the number sgn or doube number sgn characters can be used to begn
the names of other types of ob|ects, we do not recommend ths practce.
Some Transact-SOL functons have names that start wth doube at sgns (@@). To
avod confuson wth these functons, you shoud not use names that start wth @@.
Dfference between temporary tabe(#) and temporary varabe(@):
Temporary tabes cannot have foregn key constrants
Temporary tabes can have ndexes whe temporary varabe(tabe) w have
ony one ndex that accompanes the prmary key
4. Whch one of the foowng s a contro-of-fow T-SOL statement?
a. WHILE
b. IN
c. WHERE
d. ORBER BY
e. EXECUTE
Answer: WHILE
Expanaton:
These are the contro-of-fow keywords.
BEGIN...END BREAK
GOTO CONTINUE
IF...ELSE WHILE
RETURN WAITFOR
5. Whch one of the foowng keyword s NOT used wth T-SOL cursors?
a. DEALLOCATE
b. FETCH
c. MOVENEXT
d. DECLARE
e. SET
Answer: MOVENEXT
6. What s the dfference between a PRIMARY KEY and UNIOUE ndex?
a. Both PRIMARY KEY and UNIOUE ndex do not aow dupcate vaues; UNIOUE
does not aow Nu.
b. You can have more than one PRIMARY KEY and ony one UNIOUE ndex.
c. PRIMARY KEY aows dupcates; UNIOUE ndex does not.
d. You can have more than one UNIOUE ndex and ony one PRIMARY KEY.
e. Both PRIMARY KEY and UNIOUE ndex do not aow dupcate vaues; PRIMARY
aows Nu.
Answer: You can have more than one UNIOUE ndex and ony one PRIMARY KEY.
7. DECLARE @I INT
SET @I=1
IF @I=1
SELECT @I=2
SET @I=@I+1
END
What s WRONG wth the T-SOL code above?
a. It s mssng an ELSE
b. The SELECT needs to be changed to SET
c. It s mssng a BEGIN
d. The IF needs to be changed to WHILE
e. It s mssng a THEN
Answer: It s mssng a BEGIN
Expanaton:
SELECT to assgn vaues to more than one varabe at a tme. SET aows you to
assgn data to ony one varabe at a tme. Here's how:
/* Decarng varabes */
DECLARE @Varabe1 AS nt, @Varabe2 AS nt
/* Intazng two varabes at once */
SELECT @Varabe1 = 1, @Varabe2 = 2
/* The same can be done usng SET, but two SET statements are needed */
SET @Varabe1 = 1
SET @Varabe2 = 2
8. You manage a decson support system that contans numerous datetme coumns.
You are creatng vews that return the data as a strng vaue n the format yyyy-mm-
dd.
Referrng to the scenaro above, whch one of the foowng contans the T-SOL
functon or functons that you need to use n your vews n order to change datetme
vaue to a char or varchar data type?
a. CHAR
b. CAST
c. COALESCE
d. COMPUTE
e. COLLATE
Answer: CAST
Expanaton:
You can use CAST or CONVERT.
CAST(datetme AS varchar) or CONVERT(varchar,datetme)
CHAR ( nteger_expresson )
nteger_expresson - Is an nteger from 0 through 255. NULL s returned f the nteger
expresson s not n ths range.
CHAR(78) - N
COALESCE(expression1,...n) s equvaent to ths CASE expresson:
CASE
WHEN (expresson1 IS NOT NULL) THEN expresson1
...
WHEN (expressonN IS NOT NULL) THEN expressonN
ELSE NULL
END
9. UPDATE TOP(1) Customers SET FrstName=Ted WHERE LastName=Anderson
What does the above T-SOL Code do?
a. It updates a rows wth the LastName of Anderson to a FrstName of Ted
b. It updates a row wth the LastName of Anderson to a FrstName of Ted
c. It updates no rows due to an error
d. It updates a rows to a FrstName of Ted f the LastName of Anderson s not
found
e. It updates a row wth the LastName of Ted to a FrstName of Anderson
Answer: It updates a row wth the LastName of Anderson to a FrstName of Ted
10. You need to dspay a rows of data from TABLE1 and TABLE2, ncudng dupcates.
Referrng to the scenaro above, whch one of the foowng T-SOL statements do you
use?
a. SELECT * FROM TABLE1 UNION SELECT * FROM TABLE2
b. SELECT * FROM TABLE1 UNION ALL SELECT * FROM TABLE2
c. SELECT * FROM TABLE1 UNION * SELECT * FROM TABLE2
d. SELECT * FROM TABLE1 MERGE SELECT * FROM TABLE2
e. SELECT * FROM TABLE1 |OIN SELECT * FROM TABLE2
Answer: SELECT * FROM TABLE1 UNION ALL SELECT * FROM TABLE2
Expanaton: UNION ALL ncudes dupcates. UNION dspays resut set wthout
dupcates.
11. Whch one of the foowng methods do you use to create custom error messages n
SOL Server?
a. Use the xp_addmessage extended stored procedure
b. Insert a row n the syserrors tabe
c. Use the CREATE MESSAGE DDL statement
d. Use sp_addmessage system stored procedure
e. Insta the Custom Error Messages add-n from the SOL Server Resource kt
Answer: Use sp_addmessage system stored procedure
Expanaton: Stores a new user-defned error message n an nstance of the SOL
Server Database Engne. Messages stored by usng sp_addmessage can be vewed
by usng the sys.messages cataog vew.
EXEC sp_addmessage @msgnum = 60000, @severty = 16,
@msgtext = N'The tem named %s aready exsts n %s.',
@ang = 'us_engsh';
RAISERROR(60000,1,1,15,'param1') -- error, severty, state
msg_d s nt wth a defaut of NULL. msg_d for user-defned error messages can be
an nteger between 50,001 and 2,147,483,647. The combnaton of msg_d and
anguage must be unque; an error s returned f the ID aready exsts for the
specfed anguage.
12. CREATE INDEX T1ndex ON T1(F1 DESC)
Gven the T-SOL code above, what type of ndex s created on tabe T1?
a. UNIOUE
b. NONCLUSTERED
c. XML
d. CLUSTERED
e. PRIMARY KEY
Answer: NONCLUSTERED
Expanaton:
If CLUSTERED s not specfed, a noncustered ndex s created.
For tabes, exstng noncustered ndexes on tabes are rebut when a custered ndex
s created.
For ndexed vews, noncustered ndexes can be created ony on a vew that has a
unque custered ndex aready defned.
For xm ndex, use CREATE XML INDEX.
13. You need to retreve a st of ast names from a tabe wth no dupcates.
Referrng to the scenaro above, whch one of the foowng statements do you use?
a. SELECT DISTINCT LASTNAME FROM TABLE1
b. SELECT TOP 1 LASTNAME FROM TABLE1
c. SELECT LASTNAME FROM TABLE1 WHERE COUNT=1
d. SELECT LASTNAME FROM TABLE1 WHERE UNIOUE
e. SELECT INTO LASTNAME FROM TABLE1
Answer: SELECT DISTINCT LASTNAME FROM TABLE1
14. Whch one of the foowng statements regardng Custered and Noncustered ndexes
s true?
a. There can ony be one Noncustered ndex per tabe; there can be mutpe
Custered ndexes.
b. There can be mutpe Custered and Noncustered ndexes per tabe.
c. Custered and Noncustered ndexes are the same except Noncustered
ndexes sort the data rows of a tabe.
d. There can ony be one Custered ndex per tabe; there can be mutpe
Noncustered ndexes.
e. A Custered ndex aways has unque vaues; a Noncustered ndex can have
any vaues.
Answer: There can ony be one Custered ndex per tabe; there can be mutpe
Noncustered ndexes.
Expanaton:
A custered ndex s a speca type of ndex that reorders the way records n the tabe
are physcay stored.
A noncustered ndex s a speca type of ndex n whch the ogca order of the ndex
does not match the physca stored order of the rows on dsk.
When you create a PRIMARY KEY constrant, a unque custered ndex on the coumn
or coumns s automatcay created f a custered ndex on the tabe does not aready
exst and you do not specfy a unque noncustered ndex. The prmary key coumn
cannot aow NULL vaues.
When you create a UNIOUE constrant, a unque noncustered ndex s created to
enforce a UNIOUE constrant by defaut. You can specfy a unque custered ndex f a
custered ndex on the tabe does not aready exst.
Mutpe unque noncustered ndexes can be defned on a tabe.
Custered ndex can be unque or non-unque.
15. Whch one of the foowng forms of referenta ntegrty sets the vaue of a coumn
when no other vaue s specfed durng an nsert?
a. Trgger
b. Basene
c. Rue
d. Index
e. Defaut
Answer: Defaut
Expanaton:
CREATE DEFAULT phonedft AS 'unknown';
sp_bndefaut 'phonedft', 'Person.Contact.Phone';
Creates an ob|ect caed defaut. When bound to a coumn or an aas data type, a
defaut specfes a vaue to be nserted nto the coumn to whch the ob|ect s bound
(or nto a coumns, n the case of an aas data type), when no vaue s expcty
supped durng an nsert.
CREATE RULE range_rue
AS
@range>= $1000 AND @range <$20000;
EXEC sp_bndrue 'today', 'HumanResources.Empoyee.HreDate'
Creates an ob|ect caed a rue. When bound to a coumn or an aas data type, a rue
specfes the acceptabe vaues that can be nserted nto that coumn.
Use CHECK CONSTRAINTS nstead of RULE
16. SELECT * FROM TABLE1 WHERE ITEMID IN (10, 20)
What does the T-SOL statement above dspay?
a. The frst 10 to 20 rows of TABLE1.
b. A rows of ITEMID ony from TABLE1 that do not have an ITEMID of 10 and 20.
c. A rows and coumns from TABLE1 that do not have an ITEMID of 10 and 20.
d. Ony coumns of TABLE1 that contan 10 or 20 n ther name.
e. A rows and coumns from TABLE1 that contan an ITEMID of 10 or 20.
Answer: A rows and coumns from TABLE1 that contan an ITEMID of 10 or 20.
17. Whch one of the foowng s NOT a type of constrant?
a. Cascade
b. Foregn key
c. Prmary key
d. Unque
e. Check
Answer: Cascade
18. Referrng to the sampe code above, what s the endng vaue of oca varabe
@count?
a. 0
b. 1
c. 9
d. 10
e. 12
Answer: 10
19. Referrng to the sampe code above, what s the endng vaue of oca varabe
@count?
a. Nu
b. 0
c. 2
d. 8
e. 16
Answer: Nu
20. CREATE TABLE test_defauts (ID nt IDENTITY(1, 1) DEFAULT 1)
What s wrong wth the T-SOL statement above?
a. You cannot create a tabe wth ony one coumn.
b. You cannot use the nt data type on dentty feds.
c. You cannot create a defaut on an dentty fed.
d. You need to set the defaut to 0 for dentty feds.
e. You need to change the "IDENTITY(1, 1)" to "IDENTITY(nt, 1, 1)".
Answer: You cannot create a defaut on an dentty fed.
1. DECLARE @sTrue char(1)
2. DECLARE @var char(10)
3. SET @var = 'aphabet'
4. If @var LIKE '%ABC%'
5. SET @sTrue = 'Y'
6. ELSE
7. SET @sTrue = 'N'
21. Upon competon of the query batch above and assumng DEFAULT SOL Server
nstaaton, what s the vaue of @sTrue?
a. NULL--an error occurred on ne 1
b. Y
c. NULL--an error occurred on ne 4
d. N
e. NULL--an error occurred on ne 3
Answer: N
22. What s the endng vaue of varabe @Var1 n the sampe code above?
a. Nu
b. 1
c. 4
d. 5
e. 6
Answer: 4
23. Whch one of the foowng s the defaut vaue that s assgned to a varchar data type
mmedatey after t has been decared and before a vaue has been expcty
assgned to t?
a. CHAR(0)
b. The varabe s fed wth spaces.
c. CHAR(NULL)
d. NULL
e. 0
Answer: NULL
24. SELECT * FROM T1 WHERE F1 = 2
Referrng to the T-SOL code above, f an ndex does NOT exst on tabe T1, what must
SOL Server do to fnd data n the tabe?
a. Create a vew of the tabe.
b. Create a temporary ndex.
c. Perform a tabe scan.
d. Fnd the frst match and stop searchng.
e. Use a stored procedure.
Answer: Perform a tabe scan
25. If you are ogged onto SOL Server as the System Admnstrator, and you execute the
T-SOL code above, whch one of the foowng resuts do you get?
a. 1 ...\Admnstrator 123
b. 1 sa 123
c. 0 ...\Admnstrator 987
d. 0 sa 987
e. 1 dbo 987
Answer: 1 dbo 987
26. If you need to create a tabe wth a coumn that contans no dupcate vaues but
aows for a NULL vaue, whch one of the foowng ndex types do you use?
a. XML
b. Prmary Key
c. Custered
d. Non Custered
e. Unque
Answer: Unque
27. SELECT * FROM PRODUCTS WHERE PRODUCTID IN (SELECT PRODUCTID FROM
ONSALEPRODUCTS)
What does the T-SOL statement above seect?
a. A rows from PRODUCTID that have PRODUCTS n the ONSALEPRODUCTS
tabe
b. A rows from PRODUCTS that have a PRODUCTID n the PRODUCTID tabe
c. A rows from ONSALEPRODUCTS that have a PRODUCTID n the PRODUCTID
tabe
d. A rows from ONSALEPRODUCTS that have a PRODUCTID n the PRODUCTS
tabe
e. A rows from PRODUCTS that have a PRODUCTID n the ONSALEPRODUCTS
tabe
Answer: A rows from PRODUCTS that have a PRODUCTID n the ONSALEPRODUCTS
tabe
28. SELECT o.Prce, o.Cost, (SELECT MAX(.Ouantty) FROM Items as
WHERE .OrderNum = o.OrderNum) as MaxOty FROM Orders as o
What does the T-SOL statement above dspay?
a. The coumns named Prce, Cost from Items, and MaxOty from Orders
b. A coumns from Items and from Orders
c. The coumns named Prce, Cost from Orders, and Ouantty from Items
d. The coumns named Prce, Cost from Items, and Ouantty from Orders
e. The coumns named Prce, Cost from Orders, and MaxOty from Items
Answer: The coumns named Prce, Cost from orders and MaxOty from Items
29. RETURN @avar.query('Product/Prces')
The above T-SOL code s an exampe of usng whch one of the foowng data types?
a. Nvarchar
b. Varchar
c. Text
d. Ntext
e. Xm
Answer:Xm
The stored representaton of xml data type nstances cannot exceed 2 GB.
30. Whch one of the foowng types of database ob|ects s bound to a tabe and
executes a batch of code whenever a specfc data modfcaton acton occurs?
a. Trgger
b. Stored Procedure
c. Rue
d. Defaut
e. Constrant
Answer: Trgger
Creates a DML, DDL, or ogon trgger. A trgger s a speca knd of stored procedure
that automatcay executes when an event occurs n the database server. DML
trggers execute when a user tres to modfy data through a data manpuaton
anguage (DML) event. DML events are INSERT, UPDATE, or DELETE statements on a
tabe or vew.
DDL trggers execute n response to a varety of data defnton anguage (DDL)
events. These events prmary correspond to Transact-SOL CREATE, ALTER, and
DROP statements, and certan system stored procedures that perform DDL-ke
operatons. Logon trggers fre n response to the LOGON event that s rased when a
user sessons s beng estabshed. Trggers can be created n the SOL Server 2005
Database Engne drecty from Transact-SOL statements or from methods of
assembes that are created n the Mcrosoft .NET Framework common anguage
runtme (CLR) and upoaded to an nstance of SOL Server. SOL Server aows for
creatng mutpe trggers for any specfc statement.
INSTEAD OF cannot be specfed for DDL or ogon trggers.
At most, one INSTEAD OF trgger per INSERT, UPDATE, or DELETE statement can be
defned on a tabe or vew.
31. Whch one of the foowng commands and or keywords CANNOT be ncuded nsde a
trgger?
a. Truncate tabe
b. Drop ndex
c. Create procedure
d. Create ndex
e. Update statstcs
Answer: Truncate tabe
The foowng Transact-SOL statements are not aowed n a DML trgger:
ALTER DATABASE CREATE DATABASE DROP DATABASE
LOAD DATABASE LOAD LOG RECONFIGURE
RESTORE DATABASE RESTORE LOG
Addtonay, the foowng Transact-SOL statements are not aowed nsde the body of a
DML trgger when t s used aganst the tabe or vew that s the target of the trggerng
acton.
CREATE INDEX ALTER INDEX DROP
INDEX
DBCC DBREINDEX ALTER PARTITION
FUNCTION
DROP
TABLE
ALTER TABLE when used to do the foowng:
Add, modfy, or drop coumns.
Swtch parttons.
Add or drop PRIMARY KEY or UNIOUE

constrants.
32. A user connects to SOL Server, changes data wthout error, and then dsconnects.
After reconnectng at a ater tme, he sees that hs pror changes dd not save to the
database.
Whch one of the foowng caused the probem descrbed n the scenaro above?
a. The user does not have permsson to update the data.
b. The user had ogged on remotey to the database.
c. The database s set to read ony.
d. The transacton og has fed up.
e. Expct transacton mode s enabed and COMMIT TRAN was not executed.
Answer: Expct transacton mode s enabed and COMMIT TRAN was not executed.
A transacton s a sequence of operatons performed as a snge ogca unt of work. A
ogca unt of work must exhbt four propertes, caed the atomcty, consstency,
soaton, and durabty (ACID) propertes, to quafy as a transacton.
The BEGIN TRANSACTION statement ncrements @@TRANCOUNT by 1. ROLLBACK
TRANSACTION decrements @@TRANCOUNT to 0, except for ROLLBACK
TRANSACTION savepoint_name, whch does not affect @@TRANCOUNT. COMMIT
TRANSACTION or COMMIT WORK decrement @@TRANCOUNT by 1.
Expct Transactons
Expcty start a transacton through an API functon or by ssung the Transact-SOL
BEGIN TRANSACTION statement.
Autocommt Transactons
The defaut mode for the Database Engne. Each ndvdua Transact-SOL statement s
commtted when t competes. You do not have to specfy any statements to contro
transactons.
Impct Transactons
Set mpct transacton mode on through ether an API functon or the Transact-SOL
SET IMPLICIT_TRANSACTIONS ON statement. The next statement automatcay starts
a new transacton. When that transacton s competed, the next Transact-SOL
statement starts a new transacton.
Expct transacton mode asts ony for the duraton of the transacton. When the
transacton ends, the connecton returns to the transacton mode t was n before the
expct transacton was started, ether mpct or autocommt mode.
If an error prevents the successfu competon of a transacton, SOL Server
automatcay ros back the transacton and frees a resources hed by the
transacton. If the cent's network connecton to an nstance of the Database Engne
s broken, any outstandng transactons for the connecton are roed back when the
network notfes the nstance of the break. If the cent appcaton fas or f the cent
computer goes down or s restarted, ths aso breaks the connecton, and the
nstance of the Database Engne ros back any outstandng connectons when the
network notfes t of the break. If the cent ogs off the appcaton, any outstandng
transactons are roed back.
33. Lne# SOL
===== =====================
1. SELECT count(ALL),
2. co1
3. FROM ThatTabe
4. WHERE co1 IN (1-10)
5. GROUP BY co1
6. HAVING COUNT(ALL) > 3
Assumng that the co1 coumn s of the nteger data type, whch one of the foowng
nes n the sampe query above contans an error?
a. Lne 1
b. Lne 2
c. Lne 3
d. Lne 4
e. Lne 5
Answer: Lne 1
Count(dstnct exp) - dspays dstnct number count , emnates dupcates and nu
Count(a exp) - dspays number of count ncudng dupcates excudng nu
Count(*) - ncudes nu
34. If you begn a transacton, but SOL Server crashes before the transacton competes,
what happens to the transacton?
a. It causes a deadock.
b. Part of the data from the transacton s commtted.
c. The transacton s paced on hod unt you compete t.
d. It s automatcay roed back.
e. It s automatcay commtted on oadng.
Answer: It s automatcay roed back
35. SELECT ROWID
FROM (SELECT ROW_NUMBER() OVER (ORDER BY EMPLOYEEID ASC) AS ROWID, *
FROM EMPLOYEE) AS T
How many rows are dspayed from the T-SOL statement above f the EMPLOYEE tabe
has fve rows?
a. 1
b. 2
c. 3
d. 4
e. 5
Answer: 5
36. The foowng stored procedure accepts two parameters--the sma vaue shoud
never be greater than the arge vaue, though they are permtted to be equa.
Lne# SOL
----- ---------------------------
1. CREATE PROCEDURE mySP
2. (@sma nt, @arge nt) AS
3. IF @sma > @arge
4. ??
... Remanng ogc . . .
Referrng to the above scenaro, whch one of the foowng statements can you use
to ext the stored procedure at Lne 4 when the sma vaue s greater than the arge
vaue?
a. RESUME
b. END PROC
c. RETURN
d. EXIT PROC
e. END
Answer: RETURN
37. You need to store nternatona names that are mted to 100 characters n ength.
Referrng to the scenaro above, whch one of the foowng data types uses the
LEAST storage space and aows for an ndex?
a. Cursor
b. Nvarchar
c. Bnary
d. Char
e. Ntext
Answer: nvarchar
Ntext cannot be ndexed
The reason for this is that nvarchar takes twice as much space as varchar, this is
because of the need to store the extended character codes for other languages
1. Nchar(50) w aways occupy same space rrespectve of the sze of data.
2. Nvarchar(50) can store maxmum 50 characters but the actua sze depends on the
data that s stored
3. Nvarchar(Max) can store maxmum nvarchar.maxmum characters but the actua
sze depends on the data. 231-1
4. Ntext Varabe-ength Uncode data wth a maxmum ength of 230 - 1
(1,073,741,823) characters. Storage sze, n bytes, s two tmes the number of
characters entered.
Varabe-ength Uncode character data. n can be a vaue from 1 through 4,000. max
ndcates that the maxmum storage sze s 231-1 bytes. The storage sze, n bytes,
s two tmes the number of characters entered + 2 bytes.
38. You need to store a number that aways stays wthn the range of 1 to 100.
Referrng to the scenaro above, whch one of the foowng data types uses the
LEAST storage space?
a. Numerc
b. Int
c. Tnynt
d. Rea
e. Bt
Answer: tnynt
Data
type Range Storage
bigint -263 (-9,223,372,036,854,775,808) to 263-1
(9,223,372,036,854,775,807)
8 Bytes
int -231 (-2,147,483,648) to 231-1 (2,147,483,647) 4 Bytes
smallint -215 (-32,768) to 215-1 (32,767) 2 Bytes
tinyint 0 to 255 1 Byte
39. You need to create an IDENTITY fed that s abe to hande over fve bon rows of
data.
Referrng to the scenaro above, whch one of the foowng data types do you use?
a. Bgnt
b. Rea
c. Int
d. Decma
e. Foat
Answer: Bg nt
MyTable
ColA ColB ColC
2 4 6
2 4 9
3 4 6
2 4 6
1 5 6
7 5 6
seect dstnct CoA, CoB, CoC from
MyTabe
40. How many rows appear n the resut set for the TL-SOL query above?
a. 2 rows
b. 3 rows
c. 4 rows
d. 5 rows
e. 7 rows
Answer: 5 rows
Expanaton: Actua output
MyTable
ColA ColB ColC
1 5 6
2 4 6
2 4 9
3 4 6
7 5 6
41. Whch one of the foowng s a way for stored procedures to add securty to a
database?
a. By reducng network bandwdth
b. By aowng deayed bndng
c. By retanng and reusng executon pan
d. By conservng network bandwdth
e. By checkng user permssons on referenced ob|ects
Answers: By checkng user permssons on referenced ob|ects
They can reduce network traffc.
An operaton requrng hundreds of nes of Transact-SOL code can be performed
through a snge statement that executes the code n a procedure, rather than by
sendng hundreds of nes of code over the network.
They can be used as a securty mechansm.
Users can be granted permsson to execute a stored procedure even f they do not
have permsson to execute the procedure's statements drecty.
42. What s a dfference between a Stored Procedure and User defned Functons?
a. UDFs can change the server envronment or the operatng system
envronment
b. Stored procedures cannot be used n an expresson
c. Functons cannot execute stored procedures
d. Functons do not permt parameters
e. Stored procedures can return any data type n pace of ther names
Answers: Stored procedres cannot be sed in an expression
A stored procedure can return ony nteger vaue through 'return'. But a functon can
return other datatypes even tabe aso.
Stored procedures are dfferent from functons n that they do not return vaues n
pace of ther names and they cannot be used drecty n an expresson.
Stored procedures cannot be used n an expresson
Stored procedures may or may not have parameters.
Sys.sq_modues - cataog vew for procedures and functons
43. Referrng to the executon pan above, whch one of the foowng tems w you
mprove by usng an ndex?
a. Item Number 2
b. Item Number 3
c. Item Number 4
d. Item Number 6
e. Item Number 7
Answer: Item number 7
44. 1. CREATE PROCEDURE myStoredProc
2. @ID unquedentfer OUTPUT,
3. @Name varchar (32)
4. AS
5. IF @ID IS NULL
6. SET @ID = NEWID()
7. INSERT myTabe
8. (ID, Name) VALUES (@ID, @Name)
When the above stored procedure creaton scrpt s changed so that the @ID
parameter has a defaut vaue of NULL, whch one of the foowng repacements for
Lne 2 s correct?
a. OPTIONAL @ID unquedentfer DEFAULT NULL OUTPUT,
b. OPTIONAL @ID unquedentfer = NULL OUTPUT,
c. @ID unquedentfer NULL OUTPUT,
d. @ID unquedentfer = NULL OUTPUT,
e. @ID unquedentfer DEFAULT NULL OUTPUT,
Answer: @ID unquedentfer = NULL OUTPUT,
45. Whch one of the foowng statements regardng the sampe code above s true?
a. T3 w fa to be created.
b. Everythng s roed back.
c. The code, n ts entrety, consttutes a batch.
d. T3 s created, but somecoumn2 s not added.
e. "SELECT * FROM T3" dspays the coumns somecoumn1 and somecoumn2.
Answer: T3 s created, but somecoumn2 s not added.
46. Whch one of the foowng stored procedure types comes as part of SOL Server and
begns wth "xp_"?
a. System
b. CLR
c. Extended
d. Transact-SOL
e. User-defned
Answer: Extended
Expanaton: Xp_ extended sp, Sp_ system sp
47. You have been asked to store huge decma amounts n a coumn wth a precson of
35 scae of 10 for an appcaton wth whch exact numerc behavor s requred.
Referrng to the scenaro above, whch one of the foowng data types do you use?
a. Rea
b. Foat
c. Money
d. Numerc or decma
e. Bgnt
Answer: Numerc or decma
Expanaton:
Decma/Numerc - decma| (p| , s| )|
p (precson)
The maxmum tota number of decma dgts that can be stored, both to the eft and
to the rght of the decma pont. The precson must be a vaue from 1 through the
maxmum precson of 38. The defaut precson s 18.
s (scae)
The maxmum number of decma dgts that can be stored to the rght of the decma
pont. Scae can be specfed ony f precson s specfed. The defaut scae s 0.
Money has 4 decma paces
Rea and foat are approx numerc
Exact Numercs
bgnt decma
nt numerc
smant money
tnynt smamoney
bt
Approxmate Numercs
foat rea
1) CREATE PROCEDURE |dbo|.|testsp|
2) @ nt = 0,
3) @s varchar(10) = NULL
4) AS
5) BEGIN
6) SET NOCOUNT ON;
7) IF EXISTS(SELECT * FROM TEST WHERE COL1 = @s)
8) RETURN @s
9) RETURN @
10) END
EXEC testsp 0, 'heo'
48. Whch ne n the T-SOL code above s INCORRECT?
a. Lne 3
b. Lne 6
c. Lne 7
d. Lne 8
e. Lne 9
Answer: Lne 8
Expanaton:
Cannot convert varchar to type nt
When SET NOCOUNT s ON, the count s not returned. When SET NOCOUNT s OFF,
the count s returned.
RETURN s mmedate and compete and can be used at any pont to ext from a
procedure, batch, or statement bock.
RETURN |nt_exp| - return returns nt
49. What s the maxmum number of tabes that can be drecty affected by a snge
INSERT, UPDATE, or DELETE statement?
a. 1
b. 16
c. 32
d. 256
e. Unmted
Answer: 1
TRY
SELECT * FROM TABLE1;
SELECT COL1 FROM TABLE2 WHERE COL2 = 5;
END TRY
CATCH
SELECT ERROR_MESSAGE() as ErrorMessage;
END CATCH;
50. What s wrong wth the T-SOL code above?
a. The CATCH bock s mssng a BEGIN...END construct.
b. The END statements shoud be removed.
c. TRY and CATCH are mssng a BEGIN to the eft of each.
d. The TRY from END TRY shoud be removed.
e. The TRY bock s mssng a BEGIN...END construct.
Answer: TRY and CATCH are mssng a BEGIN to the eft of each
Expanaton:
BEGIN TRY..END TRY
BEGIN CATCH..END CATCH
51. In order to create a VALUE XML ndex, whch one of the foowng do you create frst?
a. A PROPERTY XML ndex
b. A prmary key ndex
c. A secondary XML ndex
d. A prmary XML ndex
e. A PATH XML ndex
Answer: A prmary XML ndex
Expanaton:
To enhance search performance, you can create secondary XML ndexes. A prmary
XML ndex must frst exst before you can create secondary ndexes. These are the
types:
PATH secondary XML ndex
VALUE secondary XML ndex
PROPERTY secondary XML ndex
52. When you create a vew wth SCHEMABINDING, what does t do?
a. It creates a new schema based on the vew name, and t bnds the vew to the
schema.
b. It prevents users wthout schema permssons from accessng the vew.
c. It aows updates to underyng tabes that automatcay update the vew.
d. It prevents the vew from beng atered.
e. It prevents the base tabe or tabes from beng modfed n a way that woud
affect the vew defnton.
Answer: It prevents the base tabe or tabes from beng modfed n a way that woud
affect the vew defnton.
SCHEMABINDING
Bnds the vew to the schema of the underyng tabe or tabes. When
SCHEMABINDING s specfed, the base tabe or tabes cannot be modfed n a way
that woud affect the vew defnton. The vew defnton tsef must frst be modfed
or dropped to remove dependences on the tabe that s to be modfed. When you
use SCHEMABINDING, the select_statement must ncude the two-part names
(schema.object) of tabes, vews, or user-defned functons that are referenced. A
referenced ob|ects must be n the same database.
Vews or tabes that partcpate n a vew created wth the SCHEMABINDING cause
cannot be dropped uness that vew s dropped or changed so that t no onger has
schema bndng. Otherwse, the Database Engne rases an error. Aso, executng
ALTER TABLE statements on tabes that partcpate n vews that have schema
bndng fa when these statements affect the vew defnton.
SCHEMABINDING cannot be specfed f the vew contans aas data type coumns
53. Referrng to the sampe code above, how many rows do the SELECT statements st?
a. 8, 8, 8
b. 4, 8, 7
c. 4, 4, 4
d. 4, 8, 6
e. 6, 4, 4
Answer: 4, 8, 7
1) begn transacton
2) nsert MyTabe vaues (1,2,3,4)
3) f @@error <> 0 goto error_hander
4) commt transacton
5)
6) error_hander:
7) roback transacton
54. Whch one of the foowng s mssng from ne 5 n the sampe code above?
a. Return
b. Ext
c. End transacton
d. Skp next
e. End
Answer: return
55. What s the resut of runnng the scrpt n the sampe code above?
a. FUNCTION dbo.t s not created because parameter @I cannot be modfed.
b. FUNCTION dbo.t s created and causes TABLE dbo.t to be dropped.
c. TABLE dbo.t and FUNCTION dbo.t are created.
d. FUNCTION dbo.t s created, but errors upon executon.
e. FUNCTION dbo.t s not created because ob|ect "dbo.t" aready exsts.
Answer: FUNCTION dbo.t s not created because ob|ect "dbo.t" aready exsts.
56. Whch one of the foowng statements creates a new, empty tabe, named TABLE2,
wth the same feds as TABLE1?
a. SELECT TOP 0 * INTO TABLE2 FROM TABLE1
b. CREATE TABLE TABLE2 (SELECT * FROM TABLE1)
c. SELECT * INTO TABLE2 FROM TABLE1 WHERE NULL
d. SELECT * INTO TABLE2 FROM TABLE1 WHERE 1=1
e. CREATE TABLE TABLE2 FROM TABLE1
Answer: SELECT TOP 0 * INTO TABLE2 FROM TABLE1
57. Whch one of the foowng methods of creatng and modfyng defauts w be
removed from future versons of SOL Server and shoud be avoded?
a. DEFAULT keyword wth ALTER TABLE
b. ADD CONSTRAINT
c. DEFAULT keyword wth CREATE INDEX
d. DEFAULT keyword wth CREATE TABLE
e. CREATE DEFAULT
Answer: CREATE DEFAULT
CREATE DEFAULT-Ths feature w be removed n a future verson of Mcrosoft SOL
Server. Avod usng ths feature n new deveopment work, and pan to modfy
appcatons that currenty use ths feature. Instead, use defaut defntons created
usng the DEFAULT keyword of ALTER TABLE or CREATE TABLE.
58. Why does a coverng ndex mprove performance?
a. A the feds n the SELECT st and the WHERE cause are wthn the ndex
pages.
b. A coverng ndex s custered.
c. A tabes are |oned by prmary keys.
d. A of the feds n the WHERE and ORDER BY cause are ndexed.
e. A coverng ndex s unque.
Answer: A the feds n the SELECT st and the WHERE cause are wthn the ndex
pages.
Expanaton:
Creatng a non-custered ndex that contans a the coumns used n a SOL query, a
technque caed ndex coverng, s a quck and easy souton to many query
performance probems. Sometmes |ust addng a coumn or two to an ndex can reay
boost the query's performance.
CREATE NONCLUSTERED INDEX IX_SaesOrderDetaCoverng
ON Saes.SaesOrderDeta
(ProductID, SpecaOfferID)
INCLUDE
(SaesOrderID, SaesOrderDetaID, UntPrce,
OrderOty, UntPrceDscount);
SELECT SaesOrderID, SaesOrderDetaID, ProductID, SpecaOfferID,
UntPrce, OrderOty, UntPrceDscount
FROM Saes.SaesOrderDeta
WHERE ProductID = 707
AND SpecaOfferID = 8
59. What s the dfference between the ISNULL and COALESCE functons?
a. ISNULL takes any number of vaues and returns the frst vaue that s not
NULL.
COALESCE takes two parameters: the vaue to check and the vaue wth whch
to repace NULLs.
b. ISNULL and COALESCE both take two parameters: the vaue to check and the
vaue wth whch to repace NULLs.
COALESCE s provded strcty for compatbty wth oder versons of SOL
Server.
c. ISNULL takes any number of vaues and combnes a vaues that are not
NULL.
COALESCE takes two parameters: the vaue to check and the vaue wth whch
to repace NULLs.
d. ISNULL takes two parameters: the vaue to check and the vaue wth whch to
repace NULLs.
COALESCE takes any number of vaues and returns the frst vaue that s not
NULL.
e. ISNULL takes two parameters: the vaue to check and the vaue wth whch to
repace NULLs.
COALESCE takes any number of vaues and combnes a vaues that are not
NULL.
Answer:
ISNULL takes two parameters: the vaue to check and the vaue wth whch to repace
NULLs.
COALESCE takes any number of vaues and returns the frst vaue that s not NULL.
Expanaton:
ISNULL ( check_expresson , repacement_vaue )
check_expresson
Is the expresson to be checked for NULL. check_expresson can be of any type.
repacement_vaue
Is the expresson to be returned f check_expresson s NULL. repacement_vaue
must have the same type as check_expressson.
60. Whch one of the foowng T-SOL statements correcty meets the requrements of the
scenaro above?
a. update Empoyees
set TaxPct = case Saary
when <= 20000 then 0.05
when between 20001 and 35000 then 0.10
when between 35001 and 60000 then 0.15
when >= 60001 then 0.2
end
b. update Empoyee
set TaxPct = case
when Saary <= 20000 then 0.05
when Saary between 20001 and 35000 then 0.10
when Saary between 35001 and 60000 then 0.15
when Saary >= 60001 then 0.2
c. update Empoyee
set TaxPct = case Saary
where <= 20000 then 0.05
where between 20001 and 35000 then 0.10
where between 35001 and 60000 then 0.15
where >= 60001 then 0.2
end
d. update Empoyees
set TaxPct = case
when Saary <= 20000 then 0.05
when Saary between 20001 and 35000 then 0.10
when Saary between 35001 and 60000 then 0.15
when Saary >= 60001 then 0.2
end
e. update Empoyee
set TaxPct = case
f Saary <= 20000 then 0.05
f Saary between 20001 and 35000 then 0.10
f Saary between 35001 and 60000 then 0.15
f Saary >= 60001 then 0.2
end
Answer:
update Empoyees
set TaxPct = case
when Saary <= 20000 then 0.05
when Saary between 20001 and 35000 then 0.10
when Saary between 35001 and 60000 then 0.15
when Saary >= 60001 then 0.2
end
Expanaton:
Smpe CASE
SELECT ProductNumber, Category =
CASE ProductLne
WHEN 'R' THEN 'Road'
WHEN 'M' THEN 'Mountan'
WHEN 'T' THEN 'Tourng'
WHEN 'S' THEN 'Other sae tems'
ELSE 'Not for sae'
END,
Name
FROM Producton.Product
ORDER BY ProductNumber;
Searched CASE
SELECT ProductNumber, Name, 'Prce Range' =
CASE
WHEN LstPrce = 0 THEN 'Mfg tem - not for resae'
WHEN LstPrce < 50 THEN 'Under $50'
WHEN LstPrce >= 50 and LstPrce < 250 THEN 'Under $250'
WHEN LstPrce >= 250 and LstPrce < 1000 THEN 'Under $1000'
ELSE 'Over $1000'
END
FROM Producton.Product
ORDER BY ProductNumber ;
SOL 1 ashok
EncryptByCert
Choice 3
Choce 5
Choice 4
Choice 1 - MOVENEXT
SOL 2 ashok
Choice 1(think so)
Choice 4
Choice 5
Choice 5
Static and keyset
Choice 4
Choice 3
Choice 2
Uni!e
Sp"depends
Choice 4
Choice 3
Unkno#n
Sq 3 ashok
Choice 3
Choice 5
Choice $%do!&t'
Choice $
Choce 3
Choice 1
S#a&na &&1 (
1.Whch one of the foowng statements about the creaton of vews n SOL Server s true
Vews cannot execute stored procedures
Vews can reference more than 1024 coumns.
Statements wthn vews may ncude the keywords ORDER BY, COMPUTE, COMPUTE BY, and
INTO.
Vews can contan statement batches.
Vews can reference temporary tabes.
2.You need to start a SOL Server Profer trace automatcay. whch one of the foowng
stored procedures do you use to begn the trace?
sp_trace_setstatus
sp_trace_generateevent
sp_trace_sete!ent
sp_trace_create
sp_trace_setfter
23.
Gven that the Data Ob|ect nterface w be used from a custom appcaton, that s NOT
wrtten n .NET,
whch one of the foowng do you use to create a Data Ob|ect nterface accessng SOL
Server 2005?
Data Access Ob|ects (DAO)
ActveX Data Ob|ects (ADO)
SOL Natve Cent OLE DB
Remote data ob|ects
|et
25.
Whch one of the foowng ock types aows for read ony access to commtted transactons?
Update
Intent
Schema
shared --ans
excusve
30.
When you need to perform compex cacuatons or access externa resources n SOL Server
2005, whch one of the foowng programmng methods do you use?
CLR user defned typ
CLR stored proc
T_Sq vew
T_S"l stored proc
SOL server management studo
31.
When s t acceptabe to specfy FILLFACTOR=100 n a CREATE INDEX statement?
When you are aowng ndex pages to become competey fed before havng to rendex
When you are not concerned about runnng out of dsk space
When you are sure the ndex vaues w never change --ans
When you woud ke the pages of the ndexes to be competey padded wth empty space
When you fee the ndex vaues are hghy voate
35.
A new pro|ect trackng appcaton s beng desgned by the deveopment team at your
company. One mportant area of the appcaton s status reportng. A status report must
have a snge dstngushng coumn as the prmary key that does not reuse vaues used n
the past, a coumn for the name of the user that entered the report, and a coumn for
textua nput of sgnfcant but not unmted sze. Whch one of the foowng s a vad
CREATE TABLE statement that satsfes the requrements n the scenaro above?
CREATE TABLE Pro|ectStatus
(ReportID nt ROWGUIDCOL PRIMARY KEY, UserName varchar (24), Report varchar (8000))
CREATE TABLE Pro|ectStatus
(ReportID nt IDENTITY (1,1) PRIMARY KEY, UserName varchar (24), Report varchar (8000))
--ans
CREATE TABLE Pro|ectStatus
(ReportID unquedentfer IDENTITY (1,1) PRIMARY KEY, UserName varchar (24), Report
varchar (8000))
CREATE TABLE Pro|ectStatus
(ReportID unquedentfer PRIMARY KEY, UserName varchar (24), Report varchar (8000))
CREATE TABLE Pro|ectStatus
(ReportID unquedentfer ROWGUIDCOL PRIMARY KEY, UserName varchar (24), Report
varchar (8000))
Table [dbo].[test]
A1 B2 C3 D4
NULL 1 -10 5
10 -5 NULL 1
5 10 20 NULL
NULL 20 5 10
-10 NULL -5 20
-5 10 NULL 2
T-SQL
select coalesce(abs(C3), A1, B2) as C3
from test where A1 = abs(-10)
What s the o!t"!t of the #-$%L select stateme&t & the "roblem abo'e(
-10
-5
5
10
20
Ans: 10
38. How do Deferred Name Resouton and Compaton ad n the desgn and
mpementaton of stored procedures?
Large changes n data cause cached executon pans to expre, resutng n
ncreased performance.
They aow stored procedures to create other SOL Server ob|ects wth the
same names at run-tme.
They aow stored procedures to contro cachng of themseves.
Tabes can be created or modfed after the stored procedure s created.
They aow stored procedures to contro cachng of other stored procedures.
Swabna BB2:
4.
Whch set of key words reated to subqueres, used wth ther proper syntax, are NOT
essentay equvaent?
Choce 1
EXISTS, = ANY
Choce 2
NOT EXISTS, NOT IN
Choce 3
EXISTS, IN
Choce 4
ALL, ANY
Choce 5
SOME, ANY
5.
Whch one of the foowng s NOT true of stored procedures?
Choce 1
Remote stored procedures are superseded by dstrbuted queres.
Choce 2
Database ob|ects can be created n stored procedures.
Choce 3
WITH ENCRYPTION converts the orgna stored procedure text to an obfuscated format.
Choce 4
SOL Server automatcay compes them on every executon.--ans
Choce 5
WITH RECOMPILE cannot be specfed for CLR stored procedures
6. When are constrants checked on a tabe wth INSTEAD OF and AFTER trggers?
Choce 1
After the INSTEAD OF trggers and before the AFTER trgger
Choce 2
Before an INSTEAD OF trgger set to execute ast by sp_settrggerorder
Choce 3
Before the INSTEAD OF and AFTER trggers
Choce 4
Before an INSTEAD OF UPDATE or INSTEAD OF INSERT trgger but after an INSTEAD OF
DELETE trgger
Choce 5
After the INSTEAD OF and AFTER trggers
7.
What s the format that aows XML-based nserts, updates, and deetes n SOL Server?
Choce 1
HTTP
Choce 2
XSL
Choce 3
SOAP
Choce 4
Updategrams or OPENXML T-SOL functon
Choce 5
IIS/ISAPI
8.
Whch one of the foowng SOL Server features aows for the abty to update data through
vews?
Choce 1
ON DELETE and ON UPDATE causes
Choce 2
Abty to ndex on computed coumns
Choce 3
User-defned functons
Choce 4
Extended propertes
Choce 5
INSTEAD OF trggers
13.
How does Dynamc Lockng beneft database performance?
Choce 1
It does not mprove or degrade ockng performance; t smpfes database admnstraton.
Choce 2
It reduces system overhead by seectng the ock type that mnmzes concurrency cost.
Choce 3
It reduces system overhead by seectng the ock type that mnmzes ockng cost.
Choce 4
It does not mprove or degrade ockng performance; t aows deveopers to gnore most
typca ockng ssues.
Choce 5
It reduces system overhead by seectng the ock type that s approprate for the task.
15.
Whch one of the foowng s NOT a DDL event?
Choce 1
DROP_PARTITION_SCHEME
Choce 2
DROP_FUNCTION
Choce 3
MODIFY_ENDPOINT
Choce 4
CREATE_ASSEMBLY
Choce 5
ALTER_CONTRACT
Swabna BB3:
7. Tabe |dbo|.|test|
COLA COLB COLC COLD
100 20 90 5
NULL 5 NULL 70
8 NULL 10 40
10 60 1 NULL
9 NULL 1 50
CREATE PROCEDURE OpenCr @OCr CURSOR VARYING OUTPUT AS
SET @OCr = CURSOR FOR
SELECT TOP 2 COLA, COLD, COLC FROM test WHERE COLB IS NULL;
OPEN @OCr;
GO

DECLARE @Crs CURSOR, @COLA nt, @COLB nt, @COLC nt, @COLD nt;
EXEC OpenCr @OCr = @Crs OUTPUT;
FETCH NEXT FROM @Crs INTO @COLA, @COLB, @COLC
WHILE (@@FETCH_STATUS <> -1)
BEGIN
FETCH NEXT FROM @Crs INTO @COLA, @COLD, @COLC
END;
CLOSE @Crs;
DEALLOCATE @Crs;

SELECT @COLA, @COLD, @COLC
What s the output from the code n the probem above?
10 60 1
8 40 10
8 NULL 10
10 NULL 1
9 50 1
Choce 2
Choce 5
Choce 1(doubt)
Choce 1
Choce 5
Choce 4
Deeted
choce 1
Choce 1
Choce 5
Choice 3
Choice 4
Choice 4
Choice 1
choice 5
Dont know (choice 1 maybe)
choice 2)
Choice 5
(choice 1)
Choice 1
Choce1(doubt)
choice
1
choice
2
Choice 2
choice
4
Choice 2
Choice 1

Potrebbero piacerti anche