SQL Server Questions and Answers – Procedural Flow

This set of SQL Server Multiple Choice Questions & Answers (MCQs) focuses on “Procedural Flow”.

1. Which of the following language is used for procedural flow in SQL Server?
a) Flow language
b) Control language
c) Control-of-flow language
d) None of the mentioned
View Answer

Answer: c
Explanation: Transact-SQL provides special words called control-of-flow language that control the flow of execution of Transact-SQL statements.

2. Point out the correct statement.
a) Control-of-flow language permits statements to be connected, related to each other, and made interdependent using programming-like constructs
b) Control-of-flow statements cannot span multiple batches, user-defined functions, or stored procedures
c) Control-of-flow words are useful when you need to direct Transact-SQL to take some kind of action
d) All of the mentioned
View Answer

Answer: d
Explanation: Without control-of-flow language, separate Transact-SQL statements are performed sequentially, as they occur.

3. Which of the following is a control flow keyword?
a) IF
b) GO
c) GOTO
d) All of the mentioned
View Answer

Answer: c
Explanation: The Transact-SQL statement or statements that follow GOTO are skipped and processing continues at the label.
advertisement
advertisement

4. Which of the following code snippet is valid control flow statement?
a)

IF (@@Error  0)
   ROLLBACK
ELSE
   COMMIT
END

b)

Note: Join free Sanfoundry classes at Telegram or Youtube
IF (@@Error  0)
   ROLLBACK

c)

advertisement
IF (@@Error  0)
   ROLLBACK
ELSE
   END

d) All of the mentioned
View Answer

Answer: a
Explanation: When the IF test evaluates to false, the optional ELSE portion of the statement lets an alternative T-SQL statement execute.
advertisement

5. Point out the wrong statement.
a) GOTO can exist within conditional control-of-flow statements, statement blocks, or procedures
b) GOTO permissions need not be granted to any user
c) GOTO statements can be nested
d) None of the mentioned
View Answer

Answer: b
Explanation: GOTO permissions default to any valid user.

6. Which of the following two Transact-SQL statements are commonly used with WHILE?
a) BREAK and CONTINUE
b) BREAK and IF
c) IF and ELSE
d) All of the mentioned
View Answer

Answer: a
Explanation: The BREAK statement exits the innermost WHILE loop and the CONTINUE statement restarts a WHILE loop.

7. Which of the following scenario makes use of BEGIN..END keyword redundant?
a) when an IF statement controls the execution of multiple Transact-SQL statement
b) when an IF statement controls the execution of only one Transact-SQL statement
c) when an IF statement controls the execution of one or more Transact-SQL statement
d) none of the mentioned
View Answer

Answer: b
Explanation: Use the BEGIN and END statements anywhere a control-of-flow statement must execute a block of two or more Transact-SQL statements.

8. The BEGIN and END statements are used when ____________
a) A WHILE loop needs to include a block of statements
b) An element of a CASE expression needs to include a block of statements
c) An IF or ELSE clause needs to include a block of statements
d) All of the mentioned
View Answer

Answer: d
Explanation: A BEGIN and END statement block must contain at least one Transact-SQL statement.

9. Which of the following components constitutes use CASE expression?
a) The primary key name to transform
b) The BEGIN keyword
c) The CASE keyword
d) Where clause defining an alias for the CASE expression
View Answer

Answer: c
Explanation: A common use of the CASE expression is to replace codes or abbreviations with more readable values.

10. The following code snippet uses the DELAY keyword to wait for ______ seconds.

WAITFOR DELAY '00:00:02';
SELECT BusinessEntityID FROM 
AdventureWorks2008R2.HumanResources.Employee;

a) 2
b) 3
c) 4
d) 5
View Answer

Answer: a
Explanation: The DELAY keyword followed by a time_to_pass before completing the WAITFOR statement. The time to wait before completing the WAITFOR statement can be up to 24 hours.

Sanfoundry Global Education & Learning Series – SQL Server.

To practice all areas of SQL Server, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.