sql complete guide
TRANSCRIPT
-
8/12/2019 SQL Complete Guide
1/96
1. It is mandatory to define at least one secondary data file for a database.State True or False.Ans. False( Some databases may not have sec database file,while others may have many )
2. Consider the following statements with respect to partitioned tables:Statement 1: Partitioned tables allows data rows to be split horiontally based on !alues in a"ey column#li"e date$
Statement 2: %&' operations#I(S)*T+ ,P%-T)+ %)')T)$ for partitioned#multiple partition$tables are different from that of a single partition table.hich of the following is applicable forabo!e/Ans Statement 1 is true, 2 is false
0. hich of the following are correct with respect to Filegroups/#Choose 2$ Ans.Filegroups apply only to data files and not log files,Once a data file is added to a
database, it cannot be moved to another filegroup
. hen creating a database+ which of the following should be considered when selecting thelocation of the database files/#Choose 0$Ans. 1.atabase files should have sufficient
space for growth, !."hoose a common location or directory to #eep the database files to
#eep things organi$ed,%. &he path specified for locating the database files should e'ist
before creating a database
. Consider the following statements with respect to 3iews:Statement 1: Inde4 on a !iew ta"es up physical storage and re5uires maintenance.Statement 2: 'ocal partitioned !iew utilises base tables that reside on the same ser!er. hichof the following is applicable for abo!e/
Ans. oth Statements 1 and ! are true
6. hich of the following are features of a local temporay stored procedure/#Choose 2$Ans. t is automatically deleted when the connection is closed, t can be e'ecuted onlyby the connection that created it
7. hich of the following are correct for temporary tables used in Stored procedures/#Choose 2$Ans. 1.*ocal temporary tables created in a stored procedure are automatically dropped
when the stored procedure e'its.,!. +lobal temporary tables are not available if the usersession in which they were created disconnects from the S* Server.
8. Consider the following statements with respect to (ested stored procedures:Statement 1 : There is no limit to the number of le!els to which procedures can be nested.Statement 2 : The number of stored procedures that can be called from within a singleprocedure is limitless.Statement 0 : - stored procedure can call itself upto a defined ma4imum limithich of the following is applicable for abo!e statements/
Ans. Statement ! and % are true, 1 is false
9. hich of the following attributes characterise System Stored Procedures/#Choose 0$Ans. 1.&he stored procedure name begins with sp-., !.&he stored procedure resides in a
esource database &he procedure is defined in a sys schema
1.Consider the following statements with respect to C'* procedures:Statement 1: C'* procedures are typically written in &icrosoft C or 3isual C;;.Statement 2: C'* procedures are safe and secure because they run within the -ppdomainboundary and it cannot access random S
-
8/12/2019 SQL Complete Guide
2/96
11. hich of the following cannot be passed as input parameter !alues to a Stored procedure/#Choose 2$
Ans. Function, /'pression
12.Consider the following statement:Select title=id+ price+ type from titles where price > dbo.-!erage?oo"Price#@comp=science@$
Ans. Scalar function
hat "ind of a ,ser %efined Function is used in the abo!e statement/12. Consider the following statements with respect to ,ser defined functions:
Statement 1: - ,ser %efined Function cannot generate permanent changes to any resourcewhose scope e4tends beyond the function.Statement 2: The only changes that can be made by the S
-
8/12/2019 SQL Complete Guide
3/96
hich of the following is applicable for the abo!e/
-. Statement 1 is true+ 2 is false
. Statement 1 is false, ! is true
C. ?oth Statements 1 and 2 are true
%. ?oth Statements 1 and 2 are false
22. hich of the following option defines a cursor that ma"es a temporary copy of the data to be used by
the cursor/
A. S&A&"
?. %B(-&IC
C. E)BS)T
%. F-ST=F*-*%
20. hich of the following options is used to retrie!e the second record from a table/
A. F/&"6 S/"O7
?. F)TCD -?S',T) 2
C. F)TCD *)'-TI3) 2
%. (one of the listed options
2. Consider the following statements with respect to cursors:
Statement 1 :Cursor processing is faster than setoriented processing and causes loc"s to be held for
shorter period of time.
Statement 2: Cursors can be used to minimie loc"ing contention for updates and deletions of a large
number of rows in a table.
hich of the following is applicable for abo!e/
-. Statement 1 is true+ 2 is false
. Statement 1 is false, ! is true
C. ?oth Statements 1 and 2 are true
%. ?oth Statements 1 and 2 are false
2. Consider the following statements with respect to use of cursors in stored procedures:
Statement 1: - stored procedure can pass cursor !ariables as output parameters only.
Statement 2: Bou must use S)')CT statement to assign a cursor to a cursor !ariable.
TCD S)C(%
-
8/12/2019 SQL Complete Guide
4/96
hich of the following is applicable for abo!e/
A. Statement 1 is true, ! is false
?. Statement 1 is false+ 2 is true
C. ?oth Statements 1 and 2 are true
%. ?oth Statements 1 and 2 are false
26. Consider the following with respect to types of cursors:
Statement 1: - global cursor defined in a stored procedure is a!ailable e!en after the connection closes.
Statement 2: - local cursor remains in scope e!en after the stored procedure that declared it terminates
which of the following is applicable for abo!e/
-. Statement 1 is true+ 2 is false
?. Statement 1 is false+ 2 is true
C. ?oth Statements 1 and 2 are true
. oth Statements 1 and ! are false
27. ?elow is a code snippet for cursor:
1 ,S) -d!entureor"s
2 G
0 %)C'-*) contact=cursor C,*S* F*
S)')CT 'ast(ame F*& Person.Contact D)*) 'ast(ame 'IE) @?H@
6 *%)* ?B 'ast(ame
7 P)( contact=cursor
8 F)TCD ()T F*& contact=cursor
9 DI') JJF)TCD=ST-T,S K
1 ?)GI(
11 &issing 'ine
12 )(%
10 &issing 'ine
1 &issing 'ine
hich of the following lines of code can be correctly fitted into the missing lines/#Choose 0$
A. F/&"6 7/2& FO4 contact-cursor
?. P)( contact=cursor
". /A**O"A&/ contact-cursor
. "*OS/ contact-cursor
-
8/12/2019 SQL Complete Guide
5/96
). -''C-T) contact=cursor
28. hich of the following cursor creation option specifies that all fetch options
#FI*ST+'-ST+P*I*+()T+*)'-TI3)+-?S',T)$ are a!ailable/
-. 'ocal
. Scroll
C. Global
%.Scroll=loc"s
29. The I(ST)-% of trigger can be applied to a !iew and triggered based on the modifications to the
!iew.
State True or False.
A. &3/
?. F-'S)
0. hich of the following is limitation of I(ST)-% of trigger/
-. I(ST)-% trigger does not support recursion
?. nly one I(ST)-% of trigger can be defined for each action on a gi!en table
C. - table cannot ha!e an I(ST)-% of trigger and F*)IG( E)B constraint with C-SC-%)
defined for the same action
. All of the listed options
01. In case of defining multiple triggers for an ,P%-T) action on a gi!en table+ which of the following arecorrect trigger order !alues/#Choose 0$
-. FI*ST
?. (()
C. -(B
%. '-ST
). S)C(%
02. For which of the following it is ideal to define nonclustered inde4es/
-.
-
8/12/2019 SQL Complete Guide
6/96
00. *eferential integrity can be enforced by using %&' triggers.
hich of the following are other methods by which the same enforcement can be achie!ed/#Choose 2$
A. 3sing Stored procedures
?. %efining inde4es
". efining foreign #ey constraints
%. %efining !iews
0. hich of the following is a perfect match with reference to an Inde4/
-. Smallest unit of data storage
?. -utomatically created at the time of creating a table
". Allows an application program to find specific data without scanning through the entire
table
%. contains information about modifications carried out in the database
0. here are S
-
8/12/2019 SQL Complete Guide
7/96
08. S5lser!er uses a wor"space for storing temporary obAects such as tables and stored procedures. This
wor"space is recreated each time the s5lser!er is restarted.
hich of the followng correctly describes the abo!e wor"space database/
-. msdb
?. model
C.master
.tempdb
09. hich of the following are correct for inde4ed !iews/#Choose 2$
A. An inde'ed view is any view that has a clustered inde' defined on it
?. The inde4ed !iew is a logical entity and is not materialied in the database
C. Bou can create only one inde4 on a !iew
. nde'ed views aid in optmi$ing performance
. -n user wants to grant all users 5uery pri!ileges on hisLher %)PT table.
hich of the following S
-
8/12/2019 SQL Complete Guide
8/96
. - set of statements is to be e4ecuted 1 times.
hich of the following constructs can we use for this tas"/
a. IF..)'S)b. :6*/
c. C-S)d. (one of the listed options
. hich of the following type of integrity is correct for the statement
'Ensures that the values in a column are within the Specified Range'?
a. ntegrit!b. omain ntegrityc. "ser #efined ntegrit!d. )ntity Integrity
6. hich of the following type of integrity maintains the relationship between tables in a database/
a. eferential ntegrityb. %omain Integrityc. ,ser %efined Integrityd. )ntity Integrity
7. hich of the following type of integrity ensures each record in a table is ,ni5ue/
a. %ata Integrityb. %omain Integrityc. ,ser %efined Integrityd. /ntity ntegrity
8. Bou wor" as a database de!eloper at -?C.Inc.com.
The -?C sales staff wants to trac" sales by multiple parameters such as age+ country to be able to spot
rele!ant sales patterns.
To produce such information you need to Aoin four tables from the highly normalied database.
hich of the following suggestion will ma"e the 5uery response time faster/Create a !iew on the four tables. Create an inde4 on the !iew
a. enormali$e the database design if possible
b. Further normalie the tablec. %efine *eferential Integrity constraints so that data can be referenced faster
9. )4amine the structure of the )&P'B))S and ()=)&P'B))S tables
employees
-
8/12/2019 SQL Complete Guide
9/96
employee=id I(T Primary Eey
first=name 3-*CD-* #2$
last=name 3-*CD-*#2$
hire=date %-T) %-T)TI&)
new=employees
employee=id I(T Primary Eey
name 3-*CD-*#$
hich of the following ,P%-T) statement is !alid for the abo!e/
a. ,P%-T) new=employees S)T name K #Select last=name NN first=name F*& employees hereemployee=id K18$
b. ,P%-T) new=employees S)T name K #S)')CT last=name NN first=name F*& employees D)*)employee=id K18$ D)*) employee=id K#S)')CT employee=id F*& new employees$
c. (one of the listed optionsd. Sub5uery in this answer will return one row !alue+ concatenated first and last name for the employee
with I% 18+ so update will be successful. hen sub5ueries are lin"ed to the parent by e5ualitycomparisons+ the parent 5uery e4pects only one row of data
. hich of the following is a !alid statement about sub 5ueries/
a. - sub5uery must be enclosed in parenthesis
b. - sub5uery must be put in the right hand side of the comparison operatorc. - sub5uery cannot contain a *%)*?B claused. - 5uery should not contain more than one sub5uery
1. %uring the maAor system upgrade+ multiple data changes are going to be made. Bou would li"e to
implement !arious changes without disturbing any of the e4isting data.
hich of the following operations do not affect any e4isting data !alues/ #Choose 0$
a. nsert b. "hanging "olumn 7amec. ncreasing column length
d. &odify datatypee. %ecreasing column lengthf. The purpose of the ,P%-T) command is e4actly what you want to a!oid. Bou should be able to
increase the data storage sie and alter a column name without affecting the internal data. Dowe!er+ adecrease in the data storage sie results in data truncation or loss. I(S)*T+ used appropriately+ addsdata but does not alter any e4isting !alues
2. Consider the following statements:
-
8/12/2019 SQL Complete Guide
10/96
C*)-T) P-*TITI( F,(CTI( SalesFigures #datetime$
-S *-(G) *IGDT F* 3-',)S
#@1L1L1990@+ @1L1L199@+ @1L1L199@$
G
hat does the abo!e partition function achie!e/
a. "reates four partitions
1) for data before 1;;%
!) for data of 1;;%
%) for data of 1;;%-ssume there is a table emp defined with columns as
emp=id smallint
emp=name char
emp=address char
hich of the following command can be issued to change the datatype of column emp=address from char
to nchar/
A A*&/ &A*/ emp A*&/ "O*347 emp-address nchar 73*'
? -'T)* C',&( emp=address of T-?') emp nchar (,''
C -'T)* C',&( emp.emp=address nchar (,''
% (one of the listed options
6 -ssume there is a table emp defined with columns as
emp=id smallint
emp=name char
emp=address char
In case you want to add a new column emp=gender after the emp=name column+ which of the following
can be used/
- -'T)* T-?') emp -%% emp=gender char (T (,''
? -'T)* T-?') -%% emp.emp=gender char (T (,''
C -'T)* T-?') emp -%% emp.emp=gender char (T (,'' -FT)* emp=name
-
8/12/2019 SQL Complete Guide
16/96
7one of the listed options
new column can be added only in the end
6 -ssume there is a table emp defined with columns as
emp=id smallint
emp=name char
emp=address te4t
In case you want to add a new column emp=gender to the abo!e table+ which of the following can be
used/
- -'T)* T-?') -%% emp.emp=gender char (T (,''
?A*&/ &A*/ emp A emp-gender char 7O& 73**
C -'T)* T-?') emp -%% -T )(% emp=gender char (T (,''
% (one of the listed options
66 Consider the following statement:
C*)-T) 3I) sales.sales=sum=!u as
S)')CT datepart#yy+ orderdate$ as @order=year@+
datepart#mm+ orderdate$ as @order=month@+
sum#totaldue$
F*& sales.sales=order
G*,P ?B datepart#yy+ orderdate$+ datepart#mm+ orderdate$
hat is the outcome of the abo!e create statement/
- Creates a simple !iew successfully.
? Create fails because deri!ed columns are not allowed in S)')CT
C "reate fails because derived columns in S/*/"& should have a name or alias associated with it
%Creates an inde4ed !iew successfully.
67 Consider the following statement:
C*)-T) 3I) sales.sales=sum=!u as
S)')CT datepart#yy+ orderdate$ as @rderBear@+
datepart#mm+ orderdate$ as @rder&onth@+
-
8/12/2019 SQL Complete Guide
17/96
sum#totaldue$ as @Total%ue@
F*& sales.sales=order
G*,P ?B datepart#yy+ orderdate$+ datepart#mm+ orderdate$
*%)* ?B rderBear+ rder&onth
hat is the outcome of the abo!e create statement/
- Creates a simple !iew successfully.
? Create fails because deri!ed columns are not allowed in S)')CT
C "reate fails because O/ clause is not allowed in this statement
% Creates an inde4ed !iew successfully.
68Consider the following statements:
C*)-T) 3I) sales.sales=sum=!u as
S)')CT datepart#yy+ orderdate$ as @rderBear@+
datepart#mm+ orderdate$ as @rder&onth@+
sum#totaldue$ as @Total%ue@
F*& sales.sales=order
G*,P ?B datepart#yy+ orderdate$+ datepart#mm+ orderdate$
S)')CT top O
F*& sales.sales=sum=!u
D)*) rderBear >K27
*%)* ?B rderBear+ rder&onth
hich of the following is applicable for abo!e statements/
- "reates a simple view, and retrieves ma'imum of five records based on the given criteria
? Create fails because the C*)-T) statement does not ha!e *%)* ?B clause
C Creates a simple !iew and retrie!es minimum of fi!e records based on the criteria
% Create fails because G*,P ?B clause is not allowed in C*)-T) statement
69 Consider the following statements:
C*)-T) 3I) hr.male=emp=!u
-
8/12/2019 SQL Complete Guide
18/96
-S
S)')CT empid+ empname+ empgender
F*& hr.employees
D)*) empgender K @&@
ITD CD)CE PTI(
,P%-T) hr.male=emp=!u
S)T empgender K @F@
D)*) empid K 11
hat is the outcome of the satements as abo!e/
- The C*)-T) statement fails because CD)CE PTI( is in!alid for create !iew
? The C*)-T) and the ,P%-T) statements go through successfully
C &he "/A&/ statement goes through but 35A&/ statement fails
% (one of the listed options
ith chec" option we cannot update the column that would change the !iew retrie!al contents
7 Consider the following statements:
C*)-T) 3I) credit=card=!u
-S
S)')CT creditcardid+ cardtype+ cardno+ e4pmonth+ e4pyear
F*& sales.creditcard
,P%-T) credit=card=!u
set e4pyear K e4pyear ; 1
D)*) e4pyear K 2
hat is the outcome of the abo!e statements/
- The C*)-T) statement fails
? &he "/A&/ and the 35A&/ statements go through successfully
C The C*)-T) statement goes through but ,P%-T) statement fails
% (one of the listed options
-
8/12/2019 SQL Complete Guide
19/96
71 Consider the following S)')CT statement:
S)')CT territoryid+ sum#totaldue$
F*& sales.salesorder
G*,P ?B territoryid
*%)* ?B territoryid
In case the same S)')CT statement can be e4actly achie!ed by using a 3I)+ which of the following
3I) definition will be correct/
- C*)-T) 3I) sales=!u -S
S)')CT territoryid+ sum#totaldue$ @Totalsales@
F*& sales.salesorder
G*,P ?B territoryid
*%)* ?B territoryid
? C*)-T) 3I) sales=!u -S
S)')CT territoryid+ sum#totaldue$ @Totalsales@
F*& sales.salesorder
*%)* ?B territoryid
C C*)-T) 3I) sales=!u -S
S)')CT territoryid+ sum#totaldue$ @Totalsales@
F*& sales.salesorder
G*,P ?B territoryid
% 7one of the listed options
!iew does not support order by+ so the select stmt cannot be e4actly created as a !iew
72 -ssume there is a new table @emp@ created with columns as empid+ empname+ empdob+ empaddress
The following statements are issued for creating inde4es:
C*)-T) RC',ST)*)% I(%) id41 ( emp#empname$
C*)-T) RC',ST)*)% I(%) id42 ( emp#empdob$
hat is the outcome of the abo!e statements/
- two clustered inde4es id41 and id42 will be created on emp table
-
8/12/2019 SQL Complete Guide
20/96
? Only one clustered inde' id'1 will be created on emp table
C nly one clustered inde4 id42 will be created on emp table
% (o inde4 will be created on emp table
only one clustered inde4 is allowed+ the second one will fail
70 -ssume there is a new table @emp@ created with columns as empid+ empname+ empdob+ empaddress
The following statements are issued for creating inde4es:
C*)-T) I(%) id41 ( emp#empname$ I(C',%)
C*)-T) R((C',ST)*)% I(%) id42 ( emp#empdob$ R-SC
hat is the outcome of the abo!e statements/
- Creates nonclustered inde4es id41 on empname and id42 on empdob+ both in descending order
? Creates clustered inde4 id41 on empname and nonclustered inde4 id42 on empdob+ both in ascending
order
" "reates non0clustered inde'es id'1 on empname and id'! on empdob, both in ascending
order
% Creates clustered inde4 id41 on empname and nonclustered inde4 id42 on empdob+ both in
descending order
default is -SC for first one
7 -ssume there is a new table @emp@ created with columns as empid+ empname+ empdob+ empaddress+
emailid
empid is the primary "ey for the abo!e table.
In addition+ a clustered inde4 is created on empdob for the table.
(ow+ users re5uire faster access to employee information based on their uni5ue emailid.
hich of the following will achie!e the re5uirement/
- Create a uni5ue clustered inde4 on emailed
? "reate a uni9ue non0clustered inde' on emailed
C Create a non uni5ue clustered inde4 on emailed
% This re5uirement cannot be met by creating inde4es
uni5ue clustered cannot be created because already one clustered ind4 e4ists
7 -ssume there is a new table @emp@ created with columns as empid+ empname+ empdob+ empaddress
The following statement is issued for creating inde4:
-
8/12/2019 SQL Complete Guide
21/96
C*)-T) I(%) id41 ( emp#empname$ I(C',%) empaddress
hat is the significance of the I(C',%) clause in the abo!e statement/
- It concatenates empaddress to empname to form the inde4
? It creates inde4 !alues for empname only if address is present#not null$
C t includes empaddress in the leaf level pages of the inde'
% (one of the listed options
"eeps address data in inde4 for immediate retrie!al
76 -ssume there is an e4isting table @emp@ with columns as empid+ empname+ empdob+ empaddress
In addition+ a nonclustered inde4 #id41$ e4ists on empdob column.
The following statements are issued :
-'T)* I(%) id41 ( emp %IS-?')
%*P I(%) emp.id41
hat is the final outcome of issuing the abo!e statements/
- &he inde' id'1 is completely removed
? The inde4 id41 is temporarily disabled
C The inde4 id41 is permanently disabled
% The statements end with e4ecution error
drop finally remo!es the inde4
77-ssume there is an e4isting table @emp@ with columns as empid+ empname+ empdob+ empaddress
In addition+ a nonclustered inde4 #id41$ e4ists on empdob column.
The following statements are issued :
-'T)* I(%) id41 ( emp %IS-?')
%*P I(%) emp.id41
-'T)* I(%) id41 ( emp *)?,I'%
hat is the final outcome of issuing the abo!e statements/
- The inde4 id41 gets recreated
? The inde4 id41 is temporarily disabled
C The inde4 id41 is permanently disabled
-
8/12/2019 SQL Complete Guide
22/96
&he statements end with e'ecution error
cannot rebuild a dropped inde4+ gi!es error
78?elow is a trigger defined :
1 ,S) master
2 G
0 C*)-T) T*IGG)* sr!=trg=*estrict(ew'ogins
( -'' S)*3)*
F* C*)-T)='GI(
6 -S
7 P*I(T @(o login creations without %?- in!ol!ement.@
8 *''?-CE
9 G
hat does the abo!e trigger achie!e
- It is a -FT)* %&' trigger that restricts addition of new users e4cept with %?- pri!ileges
? It is an I(ST)-% F trigger that restricts addition of new users e4cept with %?- pri!ileges
C t is a * trigger that restricts creation of new user logins into a server
% (one of the listed options
It is %%' trigger
79 -ssume there is an e4isting table @emp@ with columns as empid+ empname+ empdob+ empaddress
In addition+ a nonclustered inde4 #id41$ e4ists on empdob column.
Transaction processing and updates happen 2O7 on the @emp@ table.
Inde4 id41 has become fragmented and needs to be rebuilt.
hich of the following will achie!e the abo!e/
- ,se -'T)* command and disable the inde4 using %IS-?') clause and rebuild using *)?,I'% clause
? ,se -'T)* command and rebuild the inde4 using *)?,I'% clause
C 3se A*&/ command and rebuild using /3* with O7*7/ O7 clause
% *ebuild is not possible when the table is updated 2O7
-
8/12/2019 SQL Complete Guide
23/96
nline inde4ing operation ispossible with ('I() K (
8 The following trigger is created an a table called @authors@ that has columns au=id+ au=name+city
C*)-T) T*IGG)* tr=au=upd ( authors
F* I(S)*T+ ,P%-T) -S
IF ,P%-T)#city$
?)GI(
*''?-CE T*-(
)(%
G
The following statement is e4ecuted on the authors table:
,P%-T) authors
S)T city K @&,&?-I@
D)*) au=id K @11@
hat will be the outcome of the abo!e statement/
- The city for au=id K 11 is changed to &,&?-I in authors table
? The city for au=id K 11 is set to (,'' in authors table
C &he city for au-id 11 is not changed in the authors table
% (one of the listed options
,P%-T) function restricts changes to city and trigger rolls bac" update
81$ The following trigger is created an a table called @authors@ that has columns au=id+ au=name+city
C*)-T) T*IGG)* tr=au=upd ( authors
F* I(S)*T+ ,P%-T) -S
IF ,P%-T)#city$
?)GI(
*''?-CE T*-( )(%
G
The following statement is e4ecuted on the authors table:
I(S)*T authors#au=id+ au=name+city$
3-',)S #11+ @P*-E-SD@+ @&,&?-I@@$
hat will be the outcome of the abo!e statement/
-
8/12/2019 SQL Complete Guide
24/96
- - new row for au=id K 11 is inserted with name K P*-E-SD and city K &,&?-I
? No row is added for au_id = 1001
C - new row for au=id K 11 is inserted with name K P*-E-SD and city K (,''
% (one of the listed options
82$ The following trigger is created an a table called @authors@ that has columns au=id+ au=name+city
C*)-T) T*IGG)* tr=au=upd ( authors
F* I(S)*T+ ,P%-T) -S
IF ,P%-T)#city$
?)GI(
*''?-CE T*-(
)(%
G
The following statement is e4ecuted on the authors table:
I(S)*T authors#au=id+ au=name$3-',)S #11+ @P*-E-SD@$
hat will be the outcome of the abo!e statement/
- - new row for au=id K 11 is inserted with name K P*-E-SD and city K (,''
7o row is added for au-id 11
C - new row for au=id K 11 is inserted with name K P*-E-SD and city K blan"
% (one of the listed options
80$ The following trigger is created an a table called @authors@ that has columns au=id+ au=name+city
C*)-T) T*IGG)* tr=au=upd ( authorsF* ,P%-T) -S
IF ,P%-T)#city$
?)GI(
*''?-CE T*-(
)(%
G
The following statement is e4ecuted on the authors table:
I(S)*T authors#au=id+ au=name$
3-',)S #11+ @P*-E-SD@$
hat will be the outcome of the abo!e statement/
A A new row for au-id 11 is inserted with name 5ACAS6 and city 73**
? (o row is added for au=id K 11
C - new row for au=id K 11 is inserted with name K P*-E-SD and city K blan"
% (one of the listed options
-
8/12/2019 SQL Complete Guide
25/96
8$ The following trigger is created an a table called @authors@ that has columns au=id+ au=name+city
C*)-T) T*IGG)* tr=au=upd ( authors
I(ST)-% F ,P%-T) -S
P*I(T @Trigger output row updated@
G
The following statements are e4ecuted on the authors table:
I(S)*T authors#au=id+ au=name$
3-',)S #11+ @*aAee!@$
,P%-T) authors S)T au=name K @*agha!@ D)*) au=id K 11
G
S)')CT au=id+ au=name D)*) au=id K11
G
hat will be the outcome of the abo!e S)')CT statement/
A Select shows au-id 11 and au-name BaGeevB
? Select shows au=id K 11 and au=name K @*agha!@
C Select shows au=id K 11 and au=name as (,''
% (one of the listed options
8$ The following trigger is created an a table called @authors@ that has columns au=id+ au=name+city
C*)-T) T*IGG)* tr=au=upd ( authors
I(ST)-% F ,P%-T) -S
IF JJ*C,(T K *)T,*(
,P%-T) authors S)T au=name K @*aman@ D)*) au=id K 11
G
The following statements are e4ecuted on the authors table:
I(S)*T authors#au=id+ au=name$
3-',)S #11+ @*aAee!@$,P%-T) authors S)T au=name K @*agha!@ D)*) au=id K 11
G
S)')CT au=id+ au=name D)*) au=id K11
G
hat will be the outcome of the abo!e S)')CT statement/
- Select shows au=id K 11 and au=name K @*aAee!@
? Select shows au=id K 11 and au=name K @*agha!@
C Select shows au=id K 11 and au=name as (,''
Select shows au-id 11 and au-name BamanB
86$ The following trigger is scoped at database le!el:
C*)-T) T*IGG)* tr=table=audit
( %-T-?-S)
F* C*)-T)=T-?')+ -'T)*=T-?')+ %*P=T-?')
-S
*''?-CE
-
8/12/2019 SQL Complete Guide
26/96
G
The following statement is isused on table @titles@ in the database
-'T)* T-?') titles -%% new=col I(T (,''
-'T)* T-?') titles %*P C',&( new=col
hat is the final outcome of issuing the -'T)* statements/
- The new column new=col is created and dropped on table titles
? The new column new=col is created on table titles but drop fails
" "reation of new column new-col on table titles itself fails
% (one of the listed options
87$ The following trigger is created
C*)-T) T*IGG)* tr=inde4=audit
( %-T-?-S)
F* C*)-T)=I(%)+ -'T)*=T-?')+ %*P=I(%)
-S
%)C'-*) J)!ent%ata &'
S)T J)!ent%ata K )3)(T%-T-#$
S)')CT J)!ent%ata.
-
8/12/2019 SQL Complete Guide
27/96
deptid is the primary "ey
Table @emp@ holds information about employees li"e empid+ name+ deptid+ dateofbirth
deptid is the foreign "ey referencing the primary "ey deptid of table dept.
In case a department is closed+ the department row needs to be deleted from @dept@ table. Since foreign
"ey constraint e4ists+ the department row cannot be deleted if there are any employees in that
department.
To o!ercome the abo!e+ an -FT)* T*IGG)* was created on the @dept@ table with code to delete the
indi!idual employee rows based on the deptid.
hich of the following is the final outcome of issuing a %)')T) statement for a deptid in the @dept@ table/
- The employee rows in table empgets deleted and the department row in dept table is then deleted
? The employee rows in emp table alone get deleted
C The department row in dept table alone gets deleted
&he delete on dept table fails due to foreign #ey constraint and no further deletions ta#e place
on dept or emp table
9$ Consider the following scenario:
Four triggers are defined for some operations on a table.
The order of firing are defined as under:
sp=settriggerorder tr=1+ FI*ST+ @,P%-T)@
sp=settriggerorder tr=2+ (()+ @,P%-T)@
sp=settriggerorder tr=0+ '-ST+ @,P%-T)@
sp=settriggerorder tr=+ (()+ @,P%-T)@
sp=settriggerorder tr=+ (()+ @I(S)*T@
hich of the following are !alid combination of firing order for abo!e triggers in case an update operation
ta"es place on the table/#Choose 2$
A tr-1 , tr-
-
8/12/2019 SQL Complete Guide
28/96
% ?oth the Aobs and employees tables are not updated
92$ e identify a transaction ==========.
- by its name
? by its parameters
C by its performance
by its A" property
90$ hich of the following applies to S
-
8/12/2019 SQL Complete Guide
29/96
A HH&A7"O37&
? JJT*-(S
C JJT*-S-CTI(C,(T
% JJT*-(S-CTI(S
98$ hich of the following is used to locate specific content and elements within an &' document/
- P-TD
24*
C T)&P')TS
% S%
99$ &' columns can only ha!e one primary &' inde4 defined.
Dow many ma4imum secondary indices can be defined/
- 2
?
" %
% 7
1$ hich of the following is (T a !alid *eplication type/
- Transactional *eplications
? Snapshot *eplications
" &raditional eplications
% &erge *eplications
11. hich of the following command is used to !iew the &' inde4es used in the database/
1. sys.&'(_inde"es
2. sys.&'=inde4
0. sys.&'=inde4es=-''
. sys.&'=inde4es=catalog
12. hich of the following fi4ed ser!er roles can manage lin"ed ser!ers/
1. processadmin
2. setupadmin
-
8/12/2019 SQL Complete Guide
30/96
0. securityadmin
. ser!eradmin
10. Bou need to perform these tas"s:
1 Create and assign a &-(-G)* role to ?la"e and Clar"
2 Grant C*)-T) T-?') and C*)-T) 3I) pri!ileges to ?la"e and Clar"
hich of the following set of S
-
8/12/2019 SQL Complete Guide
31/96
. It is better to define two primary "ey constraints with )mp(um and ProA(um separately
16. The D* database in a company has )&P'B)) and %)P-*T&)(T tables.
%ept=id+ the primary "ey of %)P-*T&)(T table+ is defined as a foreign "ey in the )&P'B)) table
with ( %)')T) C-SC-%) optionhat happens when a department is deleted in the %)P-*T&)(T table/
1. All re!ords in +'7(6++ ta#le #elonging to tat department are deleted
2. The %ept=id column in )&P'B)) table belonging to that department is updated to spaces
0. The %ept=id in )&P'B)) table belonging to that department is set to (,''
. ,pdate fails if there are any records in )&P'B)) table for that %ept=id
17. The D* database in a company has )&P'B)) and %)P-*T&)(T tables.
%ept=id+ the primary "ey of %)P-*T&)(T table+ is defined as a foreign "ey in the )&P'B)) table
hat happens when a department+ with no associated )&P'B)) records+ is deleted in the
%)P-*T&)(T table/
1. Te 9+7A*T'+NT re!ord is deleted #ut tere is no update done on +'7(6++ ta#le
2. (o update occurs and no error is gi!en
0. -n error is returned as data integrity is !iolated
.It leads to unpredictable results
18. The D* database in a company has )&P'B)) and %)P-*T&)(T tables.
%ept=id+ the primary "ey of %)P-*T&)(T table+ is defined as a (,'' column and a foreign "ey in
)&P'B)) table.
hat happens when a department is deleted in the %)P-*T&)(T table/
1. The %)P-*T&)(T record is deleted but there is no update done on )&P'B)) table
2. Te 9+7A*T'+NT re!ord is deleted and te 9ept_id !olumn in +'7(6++ ta#el is set to null
$alues
0. The %)P-*T&)(T record is deleted and the %ept=id column in )&P'B)) tabel is set to spaces
. -n error is returned as data integrity is !iolated
19. Consider the following table #*%)*S$
rder(um -mount %-T) Cust(um
01 2 0oct9 17
00 2 0oct9 11
-
8/12/2019 SQL Complete Guide
32/96
02 0 0oct9 1
0 2 oct9 11
0 2 oct9 10
hat will be the *ow=(umber for Cust(um of 17 in the following 5uery/
select Cust(um+ sum#-mount$+
*=(,&?)* #$ 3)* #order by sum#-mount$ %)SC$ as *ow=(umber
from *%)*S group by Cust(um
order by sum#-mount$ desc
1.1
2.1
0.0
.
11. Consider the following table #*%)*S$
rder(um -mount %-T) Cust(um
01 0 0oct9 17
00 2 0oct9 11
02 0 0oct9 1
0 2 oct9 11
0 2 oct9 10
hat will be the *an" for Cust(um of 10 in the following 5uery/
select Cust(um+ sum#-mount$+
*-(E #$ 3)* #order by sum#-mount$ %)SC$ as *an"
from *%)*S group by Cust(umorder by sum#-mount$ desc
1.1
2.2
0.0
.
111. Consider the following table #*%)*S$
rder(um -mount %-T) Cust(um01 0 0oct9 17
00 2 0oct9 11
02 0 0oct9 1
0 2 oct9 11
0 2 oct9 10
hat will be the %ense=*an" for Cust(um of 10 in the following 5uery/
-
8/12/2019 SQL Complete Guide
33/96
select Cust(um+ sum#-mount$+
%)(S)=*-(E #$ 3)* #order by sum#-mount$ %)SC$ as %ense=*an"
from *%)*S group by Cust(um
order by sum#-mount$ desc
1.1
2.2
0.0
.
112. Consider a table @employees@ and a stored procedure @sp=process@
The following statements are e4ecuted:
sp=process
S)')CT O from employees
hat is the outcome of abo!e e4ecution/
1. The S)')CT statement does not e4ecute but stored procedure sp=process e4ecutes
2. The S)')CT statement e4ecutes but stored procedure sp=process does not e4ecute
0. ?oth S)')CT and stored procedure sp=process fail to e4ecute
. Bot S+(+)T and stored pro!edure sp_pro!ess e"e!ute su!!essfully
110. Consider the following statements:
C*)-T) P*C myproc
Jparm1 int+ Jparm2 int+ Jparm0 int
-S
processing done here
*)T,*(
The abo!e P*C is e4ecuted twice as below:
1$ ))C myproc Jparm1 K + + 6
2$ ))C myproc + Jparm2 K + Jparm0 K 6
hat is the outcome of e4ecuting as abo!e/
1. ith 1$ The P*C runs successfully using the parameter !alues supplied
ith 2$ The P*C runs successfully using the parameter !alues supplied
2. it 1: Te 7*) gi$e error as te parameters are not supplied properly
it 2: Te 7*) runs su!!essfully using te parameter $alues supplied
-
8/12/2019 SQL Complete Guide
34/96
0. ith 1$ The P*C runs successfully using the parameter !alues supplied
ith 2$ The P*C gi!es error as the parameters are not supplied properly
. ith 1$ The P*C gi!es error as the parameters are not supplied properly
ith 2$ The P*C gi!es error as the parameters are not supplied properly
11. To run stored procedures using C'* in S S)T T*,ST*TDB (
go
sp=configure @clr enabled@+ 1
go
0. -'T)* %-T-?-S) database> S)T T*,ST*TDB (
go
sp=configure @clr@
go
reconfigure
go
. -'T)* %-T-?-S) database> S)T T*,ST*TDB (
sp=configure @clr@
reconfigures
11. Consider the following scenario:
- company -?C has many stored procedures each one 5uerying customer database using multiple
conditions.
The %?- thin"s that ha!ing too many stored procedures is bad for maintenance and recommends to
reduce the number of procs.
hich of the following will be a solution to the abo!e recommendation/
1. se 9ynami! S( in stored pro!edures
2. ,se (ested stored procedures
0. ,se e4tended stored procedures
-
8/12/2019 SQL Complete Guide
35/96
. %rop the stored procedures that are not in use
116. Consider the following stored procedures:
C*)-T) proc main=proc
-Se4ec sub=proc1
e4ec sub=proc2
return
go
C*)-T) proc sub=proc1
-S
e4ec sub=proc2
go
C*)-T) proc sub=proc2
-S
return
Dow many times will the proc sub=proc2 get e4ecuted upon in!o"ing ))C main=proc/
1. 2 times
2. 16 times
0. 02 times
. 01 times
. (one of the listed options
117. Consider the following stored procedure:
C*)-T) P*C)%,*) Duman*esources.usp=%eleteCandidate
#
JCandidateI% I(T
$
-S
)4ecute the %)')T) statement.
%)')T) F*& Duman*esources.MobCandidate
D)*) MobCandidateI% K JCandidateI%
missing line
?)GI(
*eturn 99 to the calling program to indicate failure.
P*I(T (@-n error occurred deleting the candidate information.@
*)T,*( 99
)(%
-
8/12/2019 SQL Complete Guide
36/96
)'S)
?)GI(
*eturn to the calling program to indicate success.
P*I(T (@The Aob candidate has been deleted.@
*)T,*(
)(%
G
hich of the following is the correct statement that can be fitted in the missing line /
1. 3F >>+*** ;< 0
2. IF JJ)*** K
0. IF )*** K
. IF )*** >
118. Consider the following statement:
C*)-T) P*C create=other=proc as
))C#@C*)-T) P*C get=au=name as
Select au=name from authors
*)T,*(@$
hat is the outcome of the abo!e when create=other=proc is e4ecuted/
1. Creates a new proc get=au=name and deletes the proc create=other=proc
2. Gi!es e4ecution error
0. Creates a new proc get=au=name
. None of te listed options
119. Consider a table @employees@ and a stored procedure @sp=process@
The following statements are e4ecuted:
S)')CT O from employeessp=process
hat is the outcome of the abo!e e4ecution/
1. The S)')CT statement does not e4ecute but stored procedure sp=process e4ecutes
2. Te S+(+)T statement e"e!utes #ut stored pro!edure sp_pro!ess does not e"e!ute
-
8/12/2019 SQL Complete Guide
37/96
0. ?oth S)')CT and stored procedure sp=process fail to e4ecute
. ?oth S)')CT and stored procedure sp=process e4ecute successfully
12. Consider a table @employees@ and a stored procedure @sp=process@
The following statements are e4ecuted:
S)')CT O from employees))C sp=process
hat is the outcome of the abo!e e4ecution/
1. The S)')CT statement does not e4ecute but stored procedure sp=process e4ecutes
2. The S)')CT statement e4ecutes but stored procedure sp=process does not e4ecute
0. ?oth S)')CT and stored procedure sp=process fail to e4ecute
. Bot S+(+)T and stored pro!edure sp_pro!ess e"e!ute su!!essfully
121. Consider the following stored procedure creation:
CREATE proc sp_create_staffASEXEC sp_use_jos
!t so happens that the user "issed creating the stored procedure sp_use_jos in the dataase.
#hat will e the outco"e of the create procedure sp_create_staff as ao$e%
a. The sp_create_staff procedure is not created due to se$ere error. The sp_create_staff procedure is created with a warning errorc. The sp_create_staff procedure is created without an& 'ind of errors
d. The sp_use_jos procedure is auto"aticall& created efore sp_create_staff procedure is createde. onl& warning error if another stored procedure oject is "ising
Ans :
122. Consider the following state"ents:
CREATE (R)C "&proc *par"1 int + 1,,- *par"2 int + 2,,- *par" int + ,,AS////processing done hereRET0R
The ao$e (R)C is eecuted twice as elow:13 EXEC "&proc23 EXEC "&proc *par"1 + 4E5A06T- *par"2 + 7- *par" + 8
#hat are the $alue of para"eters passed to "&proc in oth the cases%
a. #ith 13 par"1 + ,- par"2 + ,- par" + ,#ith 23 par"1 + 1,,- par"2 + 7- par" + 8. #ith 13 9i$es error due to incorrect para"eter passing#ith 23 par"1 + 1,,- par"2 + 7- par" + 8c. #ith 13 par"1 + 1,,- par"2 + 2,,- par" + ,,#ith 23 par"1 + 1,,- par"2 + 7- par" + 8d. #ith 13 par"1 + 1,,- par"2 + 2,,- par" + ,,#ith 23 par"1 + ,- par"2 + 7- par" + 8e. #ith 13 par"1 + 1,,- par"2 + 2,,- par" + ,,#ith 23 9i$es error due to in$alid para"eter passing
-
8/12/2019 SQL Complete Guide
38/96
f. default para"eters in first case and second case onl& par"1 is default
Ans : c
12.Consider the following :
CREATE proc ad$ance_range*low "one&- *high "one&3 #!T; REC)
-
8/12/2019 SQL Complete Guide
39/96
-
8/12/2019 SQL Complete Guide
40/96
CREATE 50CT!) stripti"e*dateti"e$al dateti"e3
RET0RS dateti"e#!T; RET0RS 066 ) 066 !(0T
ASBE9!
4EC6ARE *date$al dateti"e SE6ECT *date$al + con$ertchar1,3- isnull*dateti"e$al3- getdate33- 11,3
RET0R *date$alE4
#hich of the following happens when the ao$e function is in$o'ed with 066 input%
a. The 50CT!) od& gets eecuted and 066 is returned as result. The 50CT!) od& does not get eecuted and the $alue of 066 is returnedc. The 50CT!) returns error if input is 066e. one of the listed options
Ans :
1,.Consider the following function creation:
CREATE 50CT!) do.getonl&date3RET0RS dateti"eas
BE9!4EC6ARE *date dateti"eSET *date + do.stripti"egetdate33RET0R *dateE4
Assu"e @stripti"e@ is another function alread& created.
#hich of the following state"ent is correct for the ao$e create function%
a. The CREATE function is not $alid and gi$es error. The CREATE function is $alid ut will gi$e eecution error that stripti"e is not foundc. The CREATE function is $alid and will not gi$e an& eecution error on eistence of stripti"e function.d. one of the listed optionse. one function can call another / nesting
ans : c
11.Consider the following function creation:
CREATE 50CT!) do.getonl&date3RET0RS dateti"easBE9!4EC6ARE *date dateti"eSET *date + getdate3RET0R *dateE4
#hich of the following happens due to the use of non/deter"inistic function getdate3 in the ao$e 045%
a. The CREATE function is not $alid and gi$es error.The CREATE function is $alid ut will gi$e eecution error ecause of use of non/deter"inistic function getdate3c. The CREATE function is $alid and will not gi$e an& eecution error on use of getdate3d. one of the listed optionse. getdate3 $alid uilt in non/deter"inistic function to e used
Ans : c
12. Consider the following function creation:
CREATE 50CT!) do.getonl&date3RET0RS dateti"eas
-
8/12/2019 SQL Complete Guide
41/96
BE9!4EC6ARE *date dateti"e- *rando"data intSET *date + getdate3SET *rando"data + rand3RET0R *dateE4
#hich of the following happens due to the use of non/deter"inistic functions getdate3 and rand3 in the ao$e 045%
a. The CREATE function is not $alid and gi$es error. The CREATE function is $alid ut gi$es eecution error on use of rand3c. The CREATE function is $alid ut gi$es eecution error on use of getdate3d. one of the listed optionse.rand3 is not a $alid uiltin non/deter"inistic function that can e used
Ans : a
1. Consider the following function:
CREATE 50CT!) a$erageprice&t&pe*price "one& + ,.,3RET0RS TAB6E
AS RET0R SE6ECT t&pe- a$gisnullprice- ,33 as a$g_price 5R)< titles 9R)0( B t&pe ;AD!9 a$gisnullprice- ,33 *price3
#hich of the following state"ent is correct for the function ao$e%a. !t creates a $alid in/line tale $alued function. Create fails ecause it is an in$alid t&pe of tale $alued functionc. Create fails ecause it is an in$alid t&pe of scalar functiond. one of the listed optionse. inline tale function $alid t&pe
Ans : a
1?.Consider the following se>uence of co""ands for functions:
CREATE 50CT!) a$erageprice&t&pe*price "one& + ,.,3RET0RS TAB6E
AS RET0R SE6ECT t&pe- a$gisnullprice- ,33 as a$g_price 5R)< titles 9R)0( B t&pe ;AD!9 a$gisnullprice- ,33 *price3
A6TER 50CT!) a$erageprice&t&pe*price "one& + ,.,3RET0RS *tale talet&pe $archar123 null- a$g_price "one& null3
ASBE9! !insert *tale
SE6ECT t&pe- a$gisnullprice- ,33 as a$g_price 5R)< titles 9R)0( B t&pe ;AD!9 a$gisnullprice- ,33 *price RET0RE4
#hich of the following state"ent is correct for the ao$e state"ents%
a.The CREATE fails ut A6TER succeeds.The CREATE succeeds ut A6TER failsc. Both CREATE and A6TER failsd. CREATE and A6TER go through successfull&e.cannot "odif& function fro" inline to "ulti tale
Ans :
-
8/12/2019 SQL Complete Guide
42/96
-
8/12/2019 SQL Complete Guide
43/96
Ans : c
1H. Consider the following stored procedure creation:
CREATE proc sp_chec'_authorsAS
SE6ECT au_id- au_na"e- au_last_title 5R)< authors#;ERE au_id 1,,19)
!t so happens that the authors tale is dropped and no longer eists in the dataase.
ow the following state"ent is issuedEXEC sp_chec'_authors9)
#hat will e the outco"e of the ao$e create and eecution state"ents%a. Both Create and eecution fails. Create fails ut eecution goes through without errorsc. Both Create and eecution goes through without errorsd. Create is successful ut eecution gi$es errore. since dela&ed resolution is possile create goes through- ut eecution gi$es error on "issing tale authors
Ans : d
1.Consider the following stored procedure creation:
CREATE proc sp_chec'_authorsAS BE9! SE6ECT au_id- au_na"e- au_last_title 5R)< authors
#;ERE au_id 1,,1 RET0R9)
ow the following state"ents are issued :
EXEC sp_helptet sp_chec'_authors9)
SE6ECT definition 5R)< s&s.s>l_"odules #;ERE oject_id + oject_id@sp_chec'_authors@39)
SE6ECT oject_definition [email protected]_chec'_authors@339)
#hat will e the outco"e of the ao$e state"ents issued%
a. The source code of the stored procedure sp_chec'_authors is displa&ed 2 ti"es. The source code of the stored procedure sp_chec'_authors is displa&ed oncec. The source code of the stored procedure sp_chec'_authors is displa&ed onced. The source code of the stored procedure sp_check_authors is displayed 3 timese. All three st"ts can e used to displa& source code- so ti"es
Ans : d
1?,. Consider the following state"ents:
A6TER (R)C insert_ite"s *ite"_id char?3-*ite"_na"e $archar?,3asBE9! TR!SERT !T) co"p1.do.ite""asterite"_id- ite"_na"e3DA60ES*ite"_id- *ite"_na"e3print Jew !te" addedKE4 TR
-
8/12/2019 SQL Complete Guide
44/96
BE9! CATC;eec error_handlerRET0R /1,1E4 CATC;RET0R ,
#hat is the return code if the following state"ent is eecuted%
EXEC insert_ite"s JABC4E59;K- J9ear Asse"l&K
a. ,b.-101c. 066d. /1e. one of the listed options
Ans :
11. Consider the following statements:
C*)-T) P*C sales=till=date
Jtitle !archar#1$+ Jytd=sales int ,TP,T
-S
S)')CT Jytd=sales K ytd=sales
F*& titles
where title K Jtitle
*)T,*(
The abo!e proc is e4ecuted as follows:
%)C'-*) Jsales=upto=today int
))C sales=till=date @&y e4periments with truth@+ Jsales=upto=today
Print @Sales this year until today :@ ; C(3)*T#!archar#1$+ Jsales=upto=today
hat is the outcome of e4ecuting as abo!e/
-ns:
a)
b$ 11
c$ null
d$ 1
e$ (one of the abo!e
12. Consider the following statements:C*)-T) P*C sales=till=date
-
8/12/2019 SQL Complete Guide
45/96
Jtitle !archar#1$+ Jytd=sales int ,TP,T-SS)')CT Jytd=sales K ytd=sales F*& titles where title K Jtitle*)T,*(The abo!e proc is e4ecuted as follows:%)C'-*) Jsales=upto=today int))C sales=till=date @&y e4periments with truth@+ Jsales=upto=todayPrint @Sales this year until today :@ ; C(3)*T#!archar#1$+ Jsales=upto=todayhat is the outcome of e4ecuting as abo!e/
a$ The year to date sales as pic"ed up from the titles table will be correctly displayed for the boo" @&ye4periments with truth@
b) &he year to date sales as pic#ed up from the titles table will not be correctly displayed for theboo# B4y e'periments with truthB (not sure with this answer I it was not mar#ed yellow but thefield was mar#ed JK)
c$ The P*C will gi!e error while e4ecuting
d$ (one of the listed options
10. Consider the following statements:-ssume table @titles@ e4ists with following boo"s only:'ife without fear&y e4periments with truthGone with the windC*)-T) P*C ytd=sales2 Jtitle !archar#8$-SIF (T )ISTS #S)')CT O F*& titles D)*) title K Jtitle$ *)T,*( 111S)')CT ytd=sales
from titles where title K Jtitle
*)T,*(GThe abo!e P*C is e4ecuted as follows:%)C'-*) Jstatus I(T))C Jstatus K ytd=sales2 @'ife without fear@IF Jstatus K 111
P*I(T @(o boo" with that name found@G))C Jstatus K ytd=sales2 @,ndefeated@G))C Jstatus K ytd=sales2 @Gone with the wind@IF Jstatus K 111 P*I(T @(o boo" with that name found@
GDow many times the message @(o boo" with that name found@@ will be displayed for the abo!e scenario/
a$ once
b$ twice
c) none
d$ thrice
-
8/12/2019 SQL Complete Guide
46/96
1. Consider the following statements:
C*)-T) P*C pub=test-SS)')CT pub=id+ pub=name+ city+ statecdinto UUtempfrom publishers
where statecd in #@&D@+ @-P@+ @T(@$
S)')CT pub=id+ pub=name+ city+ statecdinto Utempfrom publishers
where statecd in #@&D@+ @-P@+ @T(@$G
The following se5uence of e4ecution statements are made:
))C pub=testGS)')CT O from UUtemp 1
S)')CT O from Utemp 2
))C pub=testGS)')CT O from UUtemp 0
hat is the correct se5uence of outcome on e4ecuting the S)')CT statements mar"ed 1+2 0 as abo!e/
a$ 1$ The contents of temp table are correctly displayed 2$ The contents of temp table are correctly displayed 0$ )rror message displayed
b$ 1$ )rror message displayed
2$ The contents of temp table are correctly displayed 0$ )rror message displayed
c) 1) &he contents of temp table are correctly displayed !) /rror message displayed
%) /rror message displayed
d$ 1$ The contents of temp table are correctly displayed 2$ )rror message displayed 0$ The contents of temp table are correctly displayed
1. Consider the following statements:C*)-T) P*C pub=test-S
S)')CT pub=id+ pub=name+ city+ statecdinto UUtempfrom publishers
where statecd in #@&D@+ @-P@+ @T(@$
S)')CT pub=id+ pub=name+ city+ statecdinto Utempfrom publishers
where statecd in #@&D@+ @-P@+ @T(@$G
-
8/12/2019 SQL Complete Guide
47/96
The following se5uence of e4ecution statements are made:
))C pub=testGS)')CT O from UUtemp 1S)')CT O from Utemp 2%*P table UUtemp))C pub=testGS)')CT O from UUtemp 0
hat is the correct se5uence of outcome on e4ecuting the S)')CT statements mar"ed 1+2+0 as abo!e/
a$ 1$ The contents of temp table are correctly displayed 2$ The contents of temp table are correctly displayed 0$ )rror message displayed
b$ 1$ )rror message displayed2$ The contents of temp table are correctly displayed
0$ )rror message displayed
c$ 1$ The contents of temp table are correctly displayed 2$ )rror message displayed
0$ )rror message displayed
d) 1) &he contents of temp table are correctly displayed !) &he contents of temp table are correctly displayed %) &he contents of temp table are correctly displayed
16. Consider the following scenario e4ample:
C*)-T) P*C find=boo"s=by=type Jtypelist !archar#8$-S
))C#@select title=id+ title K substring#title+ 1+ $+ type+ price F*& titles where type in #@; Jtypelist ; @$ order by type+ title=id@$G
set 5uoted=identifier off
The stored procedure is e4ecuted as below:))C find=boo"s=by=type V@business@+ @mod=coo"@+ @trad=coo"@VG
hich of the following are correct statements for the abo!e scenario/#Choose 2$
a$ The nested stored procedure concept is used
b) Dariable list of values can be passed into the stored procedure
c) t uses dynamic s9l 9uery within a stored procedure
d$ nly three !alues can be passed into the stored procedure
17. Consider the following Stored procedures created:
C*)-T) P*C get=titles=data=by=price#Jflag tinyint+ J!alue money$
-
8/12/2019 SQL Complete Guide
48/96
-Sselect O from titles where price K J!alue
GC*)-T) P*C get=titles=data=by=ad!ance#Jflag tinyint+ J!alue money$-S
select O from titles where ad!ance K J!alueGC*)-T) P*C get=titles=data#Jflag tinyint+ J!alue money$-Sif Jflag K 1 e4ec get=titles=data=by=price J!alueelse e4ec get=titles=data=by=ad!ance J!alue
hich of the following stored procedure is functionally e5ui!alent to the abo!e set of stored procedures/
a$ C*)-T) P*C get=titles=data=by=price#Jflag tinyint+ J!alue money$-S
e4ec get=titles=data J!alueG
C*)-T) P*C get=titles=data=by=ad!ance#Jflag tinyint+ J!alue money$-S
e4ec get=titles=data J!alueGC*)-T) P*C get=titles=data#Jflag tinyint+ J!alue money$-Sif Jflag K 1 e4ec get=titles=data=by=price J!alueelse e4ec get=titles=data=by=ad!ance J!alue
b$ C*)-T) P*C get=titles=data#Jflag tinyint+ J!alue money$-S
Select O from titles where price K J!alue or ad!ance K J!alue
c) "/A&/ 5O" get-titles-data(Hflag tinyint, Hvalue money)ASif Hflag 1 select @ from titles where price Hvalueelse select @ from titles where advance Hvalue
d$ (one of the listed options
18. Consider the following statements:
C*)-T) P*C myproc Jparm1 int1+ Jparm2 int+ Jparm0 int-Sprocessing done here*)T,*(
The abo!e P*C is e4ecuted twice as below:1$ ))C myproc2$ ))C myproc Jparm1 K 6
-
8/12/2019 SQL Complete Guide
49/96
-
8/12/2019 SQL Complete Guide
50/96
C*)-T) P*C)%,*) Select?yId'ist#JproductIds 4ml$-S%)C'-*) JProducts T-?') #I% int$I(S)*T I(T JProducts #I%$ S)')CT Param3alues.I%.!alue#@.@+@3-*CD-*#2$@$F*& JproductIds.nodes#@LProductsLid@$as Param3alues#I%$S)')CT O F*& ProductsI(()* MI( JProducts p( Products.ProductI% K p.I%
hich of the following is the correct way to call the abo!e stored procedure and pass !alues/
a) /2/" Selectyd*ist HproductdsBL5roductsMLidM%LNidMLidM>LNidMLidM1=LNidMLN5roductsMB
b$ ))C Select?yId'ist JproductIdsK@P1@
c$ ))C Select?yId'ist JproductIdsK@P1@ and productIdsK@P2@
d$ ))C Select?yId'ist
11. hich of the following is the Dighest isolation le!el in S
-
8/12/2019 SQL Complete Guide
51/96
c) Access-server-name...table
d$ (one of the listed options
1. - distributed transaction is encompassing three different database ser!ers. -t the end of preparephase in a twophase commit+ two ser!ers reported successful prepare while one reported failure toprepare.
Dow would the transaction manager respond/
a) t sends a ollbac# command to all three resource managers
b$ It sends a rollbac" command to the ser!er that reported a failure to prepare
c$ Commit is issued as maAority of ser!ers reported successful prepare
d$ (ame of the ser!er which failed to prepare+ is logged for repair wor" by %?-
16. Consider the following scenario.Bour S
-
8/12/2019 SQL Complete Guide
52/96
d$ Transactions re5uiring user confirmation of update
16. hich of the following is correct for a shared loc"/
a$ It is a loc" ac5uired by a process on the resources that it intends to modify
b$ It is a loc" ac5uired by a process on a resource prior to modifying it
c) t is loc# ac9uired by a process on a resource for the duration of read
d$ (one of the listed options
1?1. - transaction attempting to modify data on a row or page on which a shared loc" is placed can
ac5uire an e4clusi!e loc" on the resource. State True or False.
T*,)
FA*S/
1?2. hen a S)')CT O command is e4ecuted on a table+ when is the shared loc" on the first row
released/
-fter all the rows are read After the first row is read
-fter the second row is read
nly when the transaction is committed or rolled bac"
1?5. - transaction attempting to modify data on a row or page on which a shared loc" is placed can
ac5uire an update loc" on the resource. State True or False.
&3/
F-'S)
1?@. Consider the following scenario:
- Table @boo"@ has the following records
id title
2 Catch22
0 *oses in %ecember
&y e4periments with Truth
-ssume a default isolation le!el of @*)-% C&&ITT)%@ for the following commands.
,ser1 has issued the following commands
?)GI( T*-(
S)')CT title F*& boo" where id K 2
,ser2 has now issued the following commands
S)')CT title F*& boo" where id K 2
hat will be the outcome/
,ser2 will be bloc"ed
3ser! will not be bloc#ed and both will proceed
,ser1@s transaction is bloc"ed and user2 will proceed
There will be a deadloc"
1?. Consider the following scenario:
- Table @boo"@ has the following records
id title
-
8/12/2019 SQL Complete Guide
53/96
2 Catch22
0 *oses in %ecember
&y e4periments with Truth
-ssume a default isolation le!el of @*)-% C&&ITT)%@ for the following commands.
,ser1 has issued the following commands
?)GI( T*-(
S)')CT title F*& boo" ITD #,P%'CE$ where id K 2
,ser2 has now issued the following commands
S)')CT title F*& boo" where id K 2
hat will be the outcome/
,ser2 will be bloc"ed
3ser! will not be bloc#ed and both will proceed
,ser1@s transaction is bloc"ed and user2 will proceed
There will be a deadloc"
(o bloc" because ,pdate loc" is compatible with Shared loc"
1??. Consider the following scenario:
- Table @boo"@ has the following records
id title
2 Catch22
0 *oses in %ecember
&y e4periments with Truth
-ssume a default isolation le!el of @*)-% C&&ITT)%@ for the following commands.
,ser1 has issued the following commands
?)GI( T*-(
S)')CT title F*& boo" ITD #,P%'CE$ where id K 2
,ser2 has now issued the following commands
S)')CT title F*& boo" ITD #,P%'CE$ where id K 2
hat will be the outcome/
3ser! will be bloc#ed
,ser2 will not be bloc"ed and both will proceed
,ser1@s transaction is bloc"ed and user2 will proceed
There will be a deadloc"
nly one transaction can ha!e the update loc" on row 2.
1?. Consider the following scenario:
- Table @boo"@ has the following records
id title
2 Catch22
0 *oses in %ecember &y e4periments with Truth
-ssume a default isolation le!el of @*)-% C&&ITT)%@ for the following commands.
,ser1 has issued the following commands
?)GI( T*-(
S)')CT title F*& boo" ITD #,P%'CE$ where id K 2
,ser2 has now issued the following commands
-
8/12/2019 SQL Complete Guide
54/96
S)')CT title F*& boo" ITD #,P%'CE$ where id K 0
hat will be the outcome/
,ser2 will be bloc"ed
3ser! will not be bloc#ed and both will proceed
,ser1@s transaction is bloc"ed and user2 will proceed
There will be a deadloc" (o bloc" as the loc"s are on separate records
1?C. Consider the following scenario:
- Table @boo"@ has the following records
id title
2 Catch22
0 *oses in %ecember
&y e4periments with Truth
-ssume a default isolation le!el of @*)-% C&&ITT)%@ for the following commands.
,ser1 has issued the following commands
?)GI( T*-(
S)')CT title F*& boo" where id K 2
,ser2 has now issued the following commands
,P%-T) boo" S)T title K @*oses in %ecember+ Second edition@ D)*) id K 2
hat will be the outcome/
,ser2 will be bloc"ed
3ser! will not be bloc#ed and both will proceed
,ser1@s transaction is bloc"ed and user2 will proceed
There will be a deadloc"
*ead Committed isolation le!el drops the shared loc" in Transaction - after the read.
1?D. Consider the following scenario:
- Table @boo"@ has the following recordsid title
2 Catch22
0 *oses in %ecember
&y e4periments with Truth
-ssume a default isolation le!el of @*)-% C&&ITT)%@ for the following commands.
,ser1 has issued the following commands
?)GI( T*-(
,P%-T) boo" S)T title K @*oses in %ecember+ Second edition@ D)*) id K 2
,ser2 has now issued the following commands
S)')CT title F*& boo" D)*) id K 2
hat will be the outcome/
3ser! will be bloc#ed
,ser2 will not be bloc"ed and both will proceed
,ser1@s transaction is bloc"ed and user2 will proceed
There will be a deadloc"
,ser2 cannot get the shared loc" on the "ey until ,ser1 gi!es up its e4clusi!e loc".
10. Consider the following scenario:
- Table @boo"@ has the following records
-
8/12/2019 SQL Complete Guide
55/96
-
8/12/2019 SQL Complete Guide
56/96
-ssume a default isolation le!el of @*)-% C&&ITT)%@ for the following commands.
,ser1 has issued the following commands
?)GI( T*-(
S)')CT title F*& boo" ITD #,P%'CE+ D'%'CE$ D)*) title li"e @He4perimentsH@
,ser2 has now issued the following commands
I(S)*T I(T boo" 3-',)S#6+ @Darry Potter and the Dalfblood Prince@$
hat will be the outcome/
3ser! will be bloc#ed
,ser2 will not be bloc"ed and both will proceed
,ser1@s transaction is bloc"ed and user2 will proceed
There will be a deadloc"
15. Consider the following scenario:
- Table @boo"@ has the following records
id title
2 Catch22
0 *oses in %ecember
&y e4periments with Truth
-ssume a default isolation le!el of @*)-% C&&ITT)%@ for the following commands.
,ser1 has issued the following commands
?)GI( T*-(
%)')T) F*& boo" D)*) title li"e @He4perimentsH@
,ser2 has now issued the following commands
I(S)*T I(T boo" 3-',)S#6+ @Darry Potter and the Dalfblood Prince@$
hat will be the outcome/
,ser2 will be bloc"ed
3ser! will not be bloc#ed and both will proceed
,ser1@s transaction is bloc"ed and user2 will proceed There will be a deadloc"
1@. Consider the following scenario:
- Table @boo"@ has the following records
id title
2 Catch22
0 *oses in %ecember
&y e4periments with Truth
-ssume a Isolation le!el of @*)-%=C&&ITT)%=S(-PSDT@ for the following commands.
,ser1 has issued the following commands
?)GI( T*-(,P%-T) boo" S)T title K @*oses in %ecember+ Second edition@ D)*) id K 2
,ser2 has now issued the following commands
S)')CT title F*& boo" D)*) id K 2
hat will be the outcome/
,ser2 will be bloc"ed
3ser! will not be bloc#ed and both will proceed
-
8/12/2019 SQL Complete Guide
57/96
,ser1@s transaction is bloc"ed and user2 will proceed
There will be a deadloc"
1. Consider the following code:
?)GI( T*-(
%)')T) F*& T-?')1
?)GI( T*-(
I(S)*T I(T T-?')2
C&&IT
,P%-T) T-?')0
C&&IT
If the update to table0 failed+ what will be the outcome/
%)')T) from T-?')1 and I(S)*T into T-?')2 are committed
I(S)*T into T-?')2 alone is committed
7one of the changes to database are committed
(one of the listed options
1?. The P'-B)* table contains these columns :
id int#9$
name !archar#2$
manager=id int#9$
In this instance+ managers are also players whom you need to display as a list.
)!aluate these T S
-
8/12/2019 SQL Complete Guide
58/96
-
8/12/2019 SQL Complete Guide
59/96
-
8/12/2019 SQL Complete Guide
60/96
Dow many uni5ue rows are retrie!ed upon e4ecuting the abo!e cursor statements/V
1 Fi!e
2 Four
0 Three
Si4
(one of the listed options
6 (e4t and first retri!e same rows
180Consider the following cursor processing statements:
%)C'-*) )mployee=Cursor C,*S* *)-%=('B F*S)')CT 'ast(ame+ First(ame+ statusF*& dbo.)mployeesD)*) 'ast(ame li"e @?H@
P)( )mployee=CursorF)TCD ()T F*& )mployee=Cursor P*I(T JJF)TCD=ST-T,SDI') JJF)TCD=ST-T,S K ?)GI( F)TCD ()T F*& )mployee=Cursor
P*I(T JJF)TCD=ST-T,S)(%
C'S) )mployee=Cursor%)-''C-T) )mployee=Cursor
#-ssume that the )mployees table has rows of employee data$hat is the !alue of JJF)TCD=ST-T,S printed in the last print statement as per abo!e/
1
2 1
% 01
2
18 VConsider the following cursor processing statements:
%)C'-*) Jcba C,*S*%)C'-*) abc C,*S* G'?-' SC*'' F*S)')CT O F*& authorsS)T Jcba K abcP)( abcF)TCD ()T F*& JcbaF)TCD ()T F*& abcF)TCD ()T F*& Jcba
-
8/12/2019 SQL Complete Guide
61/96
C'S) Jcba%)-''C-T) abc
In case the authors table had 1 author profiles+ how many authors will get retrie!ed as per abo!e
processing/V
1 Two
2 &hree
0 ne
(one
Gi!es error message both cursor and cursor !ariable used interchangeably
18 Consider the following cursor processing statements:
%)C'-*) )mployee=Cursor C,*S* F-ST=F*-*% F*S)')CT 'ast(ame+ First(ame+ statusF*& dbo.)mployeesD)*) 'ast(ame li"e @?H@F* ,P%-T)P)( )mployee=CursorF)TCD ()T F*& )mployee=CursorDI') JJF)TCD=ST-T,S K ?)GI( %)')T) )mployees D)*) current of )mployee=Cursor F)TCD ()T F*& )mployee=Cursor)(%
C'S) )mployee=Cursor%)-''C-T) )mployee=Cursor
#-ssume that the )mployees table has rows of employee data$hat is the outcome of the abo!e cursor processing/V
1 -ll employees whose lastname starts with @?@ are deleted
2 The last employee with lastname starting with @?@ alone is deleted
0 The first employee with lastname starting with @?@ alone is deleted
< +ives error message "annot updateNdelete with
fast-forward option
186 Consider the following statements:
DI') #1K1$?)GI( -ITF* TI&) @1:@ ))C sp=update=stats *-IS)***#@Statistics updated for database@+1+1$ ITD 'G)(%
hat is the outcome of the abo!e/V
-
8/12/2019 SQL Complete Guide
62/96
1 1) 3pdates the statistics for every table in the database every night at 1 A.4
!) :rite a log entry to both S* Server log and :indows 7& application log
2 1$ ,
pdates the statistics for e!ery table in the database only once at 1 -.&
2$ rite a log entry to both S
-
8/12/2019 SQL Complete Guide
63/96
S)')CT O F*& authorsP)( abcF)TCD ()T F*& JcbaF)TCD ()T F*& abcF)TCD ()T F*& JcbaC'S) Jcba%)-''C-T) abcIn case the authors table had 1 author profiles+ how many authors will get retrie!ed as per abo!e
processing/V
1 Two
2 Three
0 ne
(one
= +ives error message Since cursor variable is not set to cursor , error
occurs
189 Consider the following statements:
S)')CT deptid+name+
groupname+C-S)D)( groupname K @&ar"eting@ TD)( @*oom 1@
D)( groupname K @Duman *esources@ TD)( @*oom 2@ D)( groupname K @Production@ TD)( @*oom 0@ )'S) @*oom @ )(%F*& hr.department
hich of the following is correct e5ui!alent to the abo!e/V
1 S/*/"& deptid,
name,
groupname,
"AS/ groupname
:6/7 B4ar#etingB &6/7 Boom 1B
:6/7 B6uman esourcesB &6/7 Boom !B
:6/7 B5roductionB &6/7 Boom %B
/*S/ Boom
-
8/12/2019 SQL Complete Guide
64/96
2 S)')CT deptid+
name+
groupname+
C-S)
D)( groupname @&ar"eting@ TD)( @*oom 1@
D)( groupname @Duman *esources@ TD)( @*oom 2@
D)( groupname @Production@ TD)( @*oom 0@
)'S) @*oom @
)(%
F*& hr.departmentV
0 S)')CT deptid+
name+
groupname+
C-S) groupname
D)( groupname @&ar"eting@ TD)( @*oom 1@
D)( groupname @Duman *esources@ TD)( @*oom 2@
D)( groupname @Production@ TD)( @*oom 0@
)'S) @*oom @
)(%
F*& hr.departmentV
(one of the listed options
19 Consider the following scenario:
- proc is created as follows:
C*)-T) P*C cursor=proc Jcursor C,*S* 3-*BI(G ,TP,T-S%)C'-*) curs1 C,*S* G'?-' F* S)')CT cast#title as !archar#0$$ as title+ pubdate from titlesset Jcursor K curs1open curs1returngo(ow the following statements are e4ecuted:
-
8/12/2019 SQL Complete Guide
65/96
%)C'-*) Jcurs C,*S*))C cursor=proc Jcursor K Jcurs outputfetch curs1fetch Jcursclose curs1deallocate curs1fetch Jcursopen Jcursgo
hat is the outcome of the last fetch and open statements in abo!e/V
1 Fetch and pen both fail
2 Fetch fails but open succeeds B
0 Fetch succeeds but open fails
Fetch and open both succeed open succeeds since not fully
dealocated
191 Consider the following scenario:
- proc is created as follows:C*)-T) P*C cursor=proc Jcursor C,*S* 3-*BI(G ,TP,T-S%)C'-*) curs1 C,*S* G'?-' F* S)')CT cast#title as !archar#0$$ as title+ pubdate from titlesset Jcursor K curs1open curs1return
go
(ow the following statements are e4ecuted:%)C'-*) Jcurs C,*S*))C cursor=proc Jcursor K Jcurs outputfetch curs1fetch Jcursclose curs1deallocate curs1fetch Jcursopen Jcursfetch Jcursclose Jcurs
deallocate Jcursopen Jcursgo
hat is the outcome of the last fetch and open statements in the abo!e statements/V
1 Fetch and pen both fail
2 Fetch fails but open succeeds
-
8/12/2019 SQL Complete Guide
66/96
-
8/12/2019 SQL Complete Guide
67/96
%)C'-*) Jcurs C,*S*))C cursor=proc Jcursor K Jcurs outputfetch curs1fetch Jcursclose curs1deallocate curs1fetch Jcursopen Jcursfetch Jcursclose Jcursopen Jcursgo
hat is the outcome of the last fetch and open statements in the abo!e statements/V
1 Fetch and pen both fail
2 Fetch fails but open succeeds
0 Fetch succeeds but open fails
Fetch and open both succeed B since not deallocated+ open
wor"s
19 Consider the following cursor processing:
%)C'-*) authors=cursor F-ST=F*-*% F*S)')CT au=lname+ au=fname F*& authors*%)* ?B au=lname+ au=fnameP)( authors=cursorF)TCD ()T F*& authors=cursorF)TCD ()T F*& authors=cursor
F)TCD ()T F*& authors=cursorF)TCD ()T F*& authors=cursorC'S) authors=cursor%)-''C-T) authors=cursor
#-ssume that authors table has 2 author profiles$
hat is the outcome of e4ecuting the abo!e cursor statements/V
1 Three author profiles are retrie!ed from authors
2 ne author profile is retrie!ed from authors
0 (o author profiles are retrie!ed from authors
Four author profiles are retrievedB
Gi!es error message fast forward allows ne4t
19 Consider the following cursor processing:
%)C'-*) authors=cursor F-ST=F*-*% F*
-
8/12/2019 SQL Complete Guide
68/96
S)')CT au=lname+ au=fname F*& authors*%)* ?B au=lname+ au=fnameP)( authors=cursorF)TCD ()T F*& authors=cursorF)TCD *)'-TI3) 7 F*& authors=cursorF)TCD -?S',T) F*& authors=cursorF)TCD '-ST F*& authors=cursorC'S) authors=cursor%)-''C-T) authors=cursor
#-ssume that authors table has 2 author profiles$
hat is the outcome of e4ecuting the abo!e cursor statements/V
1 Three author profiles are retrie!ed from authors
2 ne author profile is retrie!ed from authors
0 (o author profiles are retrie!ed from authors
Four author profiles are retrie!ed
= +ives error message with fast forward ne't only is allowed
196 Consider the following temporary stored procedure:
C*)-T) P*C)%,*) Uuse=temp-SS)')CT 1L*)T,*( JJ)***GThe following statements are e4ecuted in a procedure:
IF (T )ISTS#S)')CT productid F*& production.product D)*) color K @yellow@ $?)GI( *)T,*()(%
S)')CT productid F*& production.product D)*) color K @yellow@%)C'-*) J)rrorCode I(T))C J)rrorCode I(T K Uuse=tempP*I(T J)rrorCode
-ssuming that there is no product with yellow color+ what is the final outcome of e4ecuting as abo!e/V1 Prints error message and error code
2 /'ecutes with no message B
0 Se!ere database error
(one of the listed options since not e4ists is satisfied+Aust returns
no message
197 Consider the following temporary stored procedure:
-
8/12/2019 SQL Complete Guide
69/96
C*)-T) P*C)%,*) Uuse=temp-SS)')CT 1L*)T,*( JJ)***GThe following statements are e4ecuted in a procedure:IF (T )ISTS#S)')CT productid F*& production.product D)*) color K @yellow@ $?)GI( *)T,*()(%
S)')CT productid F*& production.product D)*) color K @red@%)C'-*) J)rrorCode I(T))C J)rrorCode I(T K Uuse=tempP*I(T J)rrorCode
-ssuming that the database has products with red+ yellow and blue colors+ what is the final outcome ofe4ecuting as abo!e/V1 5rints error message and error code B
2 )4ecutes with no message
0 Se!ere database error
(one of the listed options since temp proc is in!o"ed+ it gi!es
di!ide by error and error message is printed
198 Consider the following statements:
S)')CT deptid+name+
groupname+C-S) groupname
D)( @&ar"eting@ TD)( @*oom 1@ D)( @Duman *esources@ TD)( @*oom 2@ D)( @Production@ TD)( @*oom 0@ )'S) @*oom @ )(%F*& hr.department
hich of the following is correct e5ui!alent to the abo!e/V1 VS)')CT deptid+
name+
groupname+
C-S) groupname
D)( groupname K @&ar"eting@ TD)( @*oom 1@
D)( groupname K @Duman *esources@ TD)( @*oom 2@
D)( groupname K @Production@ TD)( @*oom 0@
-
8/12/2019 SQL Complete Guide
70/96
-
8/12/2019 SQL Complete Guide
71/96
:6/7 groupname B6uman esourcesB &6/7 Boom !B
:6/7 groupname B5roductionB &6/7 Boom %B
/*S/ Boom
-
8/12/2019 SQL Complete Guide
72/96
F)TCD C1*)T,*(G
C*)-T) P*C sp=one-SS)T ( C,(T ( %)C'-*) C,*S* C1 'C-' F* S)')CT titleid+ type from titles P)( C1F)TCD C1
))C sp=two C'S) C1 %)-''C-T) C1G#-ssume that titles table has 1 boo" titles$
hat are the possible outcomes when proc sp=one is e4ecuted/#Choose 2$V
1 One row is fetched from titles B
2 Two rows are fetched from titles
0 (o rows are fetched from titles
+ives error message B since local cursor used+ only one row+ and
sp=two gi!es error that c1 is in!alid
21. Consider the following cursor processing:
The following procedures are created:
C*)-T) P*C sp=two -S S)T ( C,(T (
%)C'-*) C,*S* C1 'C-' F* S)')CT au=id+ au=name form authors
P)( C1
F)TCD C1
C'S) C1
%)-''C-T) C1
*)T,*(
G
C*)-T) P*C sp=one -S S)T ( C,(T (
%)C'-*) C,*S* C1 'C-' F* S)')CT titleid+ type from titles
P)( C1
-
8/12/2019 SQL Complete Guide
73/96
F)TCD C1
))C sp=two
C'S) C1
%)-''C-T) C1
G
hat is the possible outcome when proc sp=one is e4ecuted/
(o rows are fetched from either titles or authors
ne row fetched from titles and no rows from authors
ne row ea! is fet!ed from titles and autors
B
Gi!es e4ecution error message
'ocal cursors can be with same name+ hence !alid and one row fetched from authors and titles each
22.
Consider the following cursor processing:
The following procedures are created:
C*)-T) P*C sp=two -S S)T ( C,(T (
%)C'-*) C,*S* C2 G?-' F* S)')CT au=id+ au=name form authors
P)( C2
*)T,*(
G
C*)-T) P*C sp=one -S S)T ( C,(T (
%)C'-*) C,*S* C1 'C-' F* S)')CT titleid+ type from titles
P)( C1
F)TCD C1
))C sp=two
F)TCD C2
C'S) C1
%)-''C-T) C1
C'S) C2
%)-''C-T) C2
-
8/12/2019 SQL Complete Guide
74/96
*)T,*(
G
#-ssume that titles table has 1 boo" titles and authors table has 2 author profiles$
hat is the possible outcome when proc sp=one is e4ecuted///
ne #ooE title is fet!ed from titles and one autor profile is fet!ed from autors
ne boo" title is fetched from titles
ne author profile is fetched from authors
Gi!es e4ecution error message
Since cursor is open+ fetch of c2 from sp=one should wor"
20.
Consider the following cursor processing:
The following procedures are created:
C*)-T) P*C sp=two -S S)T ( C,(T ( %)C'-*) C,*S* C2 G?-' F* S)')CT au=id+au=name form authors
P)( C2
*)T,*(
G
C*)-T) P*C sp=one -S S)T ( C,(T ( %)C'-*) C,*S* C1 'C-' F* S)')CT titleid+type from titles
P)( C1
F)TCD C1
))C sp=two
F)TCD C2
C'S) C1
%)-''C-T) C1
*)T,*(
G
#-ssume that titles table has 1 boo" titles and authors table has 2 author profiles$
The abo!e is e4ecuted as follows:
))C sp=one
G
-
8/12/2019 SQL Complete Guide
75/96
F)TCD C2
G
hat is the possible outcome of the abo!e e4ecution/
ne boo" title is fetched from titles and one author profile is fetched from authors
ne #ooE title is fet!ed from titles and two autor profiles are fet!ed from autors
ne boo" title is fetched from titles
Gi!es e4ecution error message
since cursor is not deallocated+ it is a!ailable e!en after sp=one finishes e4ecution and hence c2 isa!ailable for fetch
2.
Consider the following cursor processing statements:
%)C'-*) Jau=lname !archar#$+ Jau=fname !archar#2$
%)C'-*) authors=cursor C,*S* RF-ST=F*-*% F*
S)')CT au=lname+ au=fname F*& authors
D)*) au=lname 'IE) @?H@ P)( authors=cursor
F)TCD ()T F*& authors=cursor
I(T Jau=lname+ Jau=fname
DI') JJF)TCD=ST-T,S K
?)GI(
P*I(T @-uthor: @ ; Jau=fname ; @ @ ; Jau=lname
F)TCD ()T F*& authors=cursor
I(T Jau=lname+ Jau=fname
)(%
C'S) authors=cursor
%)-''C-T) authors=cursor
G
In case the authors table has authors with following entries
au=lname au=fname
?D-*-T IB)*
-
8/12/2019 SQL Complete Guide
76/96
-SDISD &-'DT*-
?I%B,T TD-E,*
-(ISD &-T*)
?-'- S,?*-&-(I-(
Dow many author names would ha!e got printed at the end as per the cursor processing abo!e/
Fi!e authors
Tree autors
(o authors
Gi!es error message
2.
Consider the following cursor processing statements:
%)C'-*) authors=cursor C,*S* F* S)')CT au=id+ au=fname+ au=lname
F*& authors D)*) state K @,T@ *%)* ?B au=id
P)( authors=cursor
IF JJC,*S*=*S K
?)GI(
C'S) authors=cursor
%)-''C-T) authors=cursor
*)T,*(
)(%
F)TCD ()T F*& authors=cursor
IF JJF)TCD=ST-T,S K 1
P*I(T @ ( *S F,(% @
)'S)
DI') JJF)TCD=ST-T,S K
?)GI(
P*I(T @-T')-ST () * F,(% @
F)TCD ()T F*& authors=cursor
)(%
-
8/12/2019 SQL Complete Guide
77/96
)(%
C'S) authors=cursor
%)-''C-T) authors=cursor
hat is the message that gets printed in case the authors table does not ha!e any rows satisfying the
gi!en condition/
7rints message N *S FN9
Prints message @-T')-ST () * F,(%@
Prints no message
Gi!es error message
Since cursor rows is chec"ed and returned+ no message is printed
26.
Sham has to con!ert the rows of the @)mployee@ table to a 4ml file+ adhering to the following rules :
1.The !alues in each row should be the property of the @row@ tag
2.Create another file in which the column name must be the tag name for each !alue
0.*oot tag must ha!e the name as @*T@ and each and e!ery row must start with the tag name @*@
.*oot tag must ha!e a property specifying the 4ml (amespace
Per *ule 1+ which of the following Centric method should Sham use to create the file/
)lement Centric
Attri#ute )entri!
ml Centric
(one of the listed options
27.
Sham has to con!ert the rows of the @)mployee@ table to a 4ml file+ adhering to the following rules :
1.The !alues in each row should be the property of the @row@ tag
2.Create another file in which the column name must be the tag name for each !alue
0.*oot tag must ha!e the name as @*T@ and each and e!ery row must start with the tag name @*@
.*oot tag must ha!e a property specifying the 4ml (amespace
Per the *ule 2+ which of the following
-
8/12/2019 SQL Complete Guide
78/96
-
8/12/2019 SQL Complete Guide
79/96
-
8/12/2019 SQL Complete Guide
80/96
-,T
+&7(3)3T
B
(one of the listed options
210.
Consider the following statement:
ith 4mlnamespaces
#
@http:LLschemas.microsoft.com as act
$
S)')CT (-&)+-%%*)SS.5uery#@LLact:email@$ F*& P)*S(-'=%)T-I'S
F* &' *-#@contactaddress@$+*T#@contact%etails$
-
8/12/2019 SQL Complete Guide
81/96
hile searching the name in the 4ml file using the
-
8/12/2019 SQL Complete Guide
82/96
-
8/12/2019 SQL Complete Guide
83/96
*T 4mlns:4siKVhttp:LLwww.w0.orgL21L&'SchemainstanceV>
CDI'%>
id>1Lid>
contents>tableLcontents>
LCDI'%>
CDI'%>
id>Lid>
contents>chairLcontents>
LCDI'%>
L*T>
Identify the
-
8/12/2019 SQL Complete Guide
84/96
b. &he 9uery returns a 'ml result set in a 'ml schematic way
c. The 5uery gets e4ecuted and returns a result set which is not a &' format
d. )rror in the abo!e statement
222. Consider the following statement:
1.S)')CT TP 1 I%+C(T)(TS F*& S-')S
2.MI(
0.P,*CD-S) on P,*CD-S).I%KS-')S.I%
.F* &' *-#@CDI'%@$+)lements SI(I'+ *T#@*T@$+&'SCD)&-
.?I(-*B
hich of the following can be added in the th line from the following which helps in )ncoding the ?inary
data that is Supported in S
contents contentstableKVchairV L>
c. contentTable contentsKVtableV L>
contentTable contentsKVchairV L>
d. contentsTable contentKVtableV L>
contentsTable contentKVchairV L>
[email protected] the following two statements:
-
8/12/2019 SQL Complete Guide
85/96
-
8/12/2019 SQL Complete Guide
86/96
S)')CT C(T)(TS @processinginstruction#C(T$@+
#select I% @data#$@from item for 4ml path#@@$$ @wor"Lwor"erLJid@
F*& IT)&
F* &' P-TD#@P*%,CTIT)&S@$+*T#@P*%,CT@$
hat is the result of the abo!e statement/
a. P*%,CT>
P*%,CTIT)&S>
/C(T table/>
wor">
wor"er idKV1 2 V L>
Lwor">
LP*%,CTIT)&S>
P*%,CTIT)&S>
/C(T chair/>
wor">
wor"er idKV1 2 V L>
Lwor">
LP*%,CTIT)&S>
LP*%,CT>
b. P*%,CT>
P*%,CTIT)&S>
/C(T table/>
wor">
wor"er idKV1 2 V L>
Lwor">
/C(T chair/> wor">
wor"er idKV1 2 V L>
Lwor">
LP*%,CTIT)&S>
LP*%,CT>
c. P*%,CT>
P*%,CTIT)&S>
wor">
wor"er idKV1 2 V L>
Lwor"> LP*%,CTIT)&S>
P*%,CTIT)&S>
wor">
wor"er idKV1 2 V L>
Lwor">
LP*%,CTIT)&S>
LP*%,CT>
-
8/12/2019 SQL Complete Guide
87/96
d. P*%,CT>
P*%,CTIT)&S>
/C(T table/>
wor"er idKV1 2 V L>
LP*%,CTIT)&S>
P*%,CTIT)&S>
/C(T chair/>
wor"er idKV1 2 V L>
LP*%,CTIT)&S>
LP*%,CT>
22C.hich of the following statement helps in ta"ing a Column @C(T)(TS@ !alue as a Comment which
is prefi4ed with @Comments:@ in F* &' /
a. S)')CT I%+ @Comments: @ ; contents @te4t#$@ F*& IT)&
F* &' P-TD#@P*%,CTIT)&S@$+*T#@P*%,CT@$
b. S/*/"& , B"ommentsE B P contents Bcomment()B FO4 &/4
FO 24* 5A&6(B5O3"&&/4SB),OO&(B5O3"&B)
c. S)')CT I%+ contents @comment#$@ ; @ Comments :@ F*& IT)&
F* &' P-TD#@P*%,CTIT)&S@$+*T#@P*%,CT@$
d. S)')CT I%+ contents as @comment#$@ F*& IT)&
F* &' P-TD#@P*%,CTIT)&S@$+*T#@P*%,CT@$
22D.Consider the following output :
P*%,CT>
P*%,CTIT)&S>
/C(T table/> wor">
wor"er idKV1 2 0 V L>
Lwor">
LP*%,CTIT)&S>
Dere+ the !alue for I% attribute are ta"en from I% column of the Item table.
hich of the following node helps us in obtaining it/
a. te4t#$
b. comment#$
c. processinginstruction#$
d. ata()
250.Consider the following table and the ,TP,T:
IT)&
I% C(T)(TS
-
8/12/2019 SQL Complete Guide
88/96
1 Table
2 Chair
,TP,T:
P*%,CT>
P*%,C