SQL Server Questions and Answers – Error Handling

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

1. Which of the following blocks are used for error handling in SQL Server?
a) TRY…CATCH
b) TRY…FINAL
c) TRY…END
d) CATCH…TRY
View Answer

Answer: a
Explanation: SQL Server 2005 introduced TRY…CATCH statement which helps us to handle the errors effectively in the back end.

2. Point out the correct statement.
a) While executing some DML Statement like INSERT, DELETE, UPDATE we can handle the error for checking proper output
b) If transaction fails, then we need to commit – This can be done by error handling
c) If transaction succeeds, then we need to rollback – This can be done by error handling
d) None of the mentioned
View Answer

Answer: a
Explanation: SQL Server also has an exception model to handle exceptions and errors that occurs in T-SQL statements.

3. Which of the following statements can be checked for Errors?
a) CREATE
b) DROP
c) DELETE
d) INSERT
View Answer

Answer: d
Explanation: DML statements can be checked for handling errors.
advertisement
advertisement

4. Purpose of TRY…CATCH block in SQL Server is ___________
a) Error handling
b) Stored Procedure handling
c) Message handling
d) None of the mentioned
View Answer

Answer: a
Explanation: TRY… CATCH implements error handling for Transact-SQL that is similar to the exception handling in the Microsoft Visual C#.

5. Point out the wrong statement.
a) If an error occurs in the TRY block, control is not passed to another group of statements that is enclosed in a CATCH block
b) If an error occurs in the TRY block, control is passed to another group of statements that is enclosed in a CATCH block
c) If an error does not occur in the TRY block, control is passed to another group of statements that is enclosed in a CATCH block
d) None of the mentioned
View Answer

Answer: b
Explanation: A TRY…CATCH construct catches all execution errors that have a severity higher than 10 that do not close the database connection.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. Which of the following benefit does Exception handling with the TRY and CATCH blocks provide?
a) Exceptions provide a mechanism to signal errors directly rather than using some side effects
b) Exceptions can be seen by the programmer and checked during the compilation process
c) Exceptions provide a clean way to check for errors without cluttering code
d) All of the mentioned
View Answer

Answer: d
Explanation: Exception handling using the TRY and CATCH statements is the common way that modern programming languages like C# and Java treat errors.

7. Exception handling is possible in SQL Server using _____________
a) THROW
b) FINAL
c) FINALLY
d) All of the mentioned
View Answer

Answer: a
Explanation: Generates an error message and initiates error processing for the session.
advertisement

8. Which of the following is an Error function used within CATCH block?
a) ERROR_STATE()
b) ERROR_STATUS()
c) ERROR_MSG()
d) All of the mentioned
View Answer

Answer: a
Explanation: ERROR_STATE() returns the state number of the error.

9. ERROR_SEVERITY() returns the ________level of the error.
a) State number
b) Full text
c) Severity
d) None of the mentioned
View Answer

Answer: c
Explanation: ERROR_SEVERITY() returns the severity level of the error.
advertisement

10. Which of the following is a global variable for error handling?
a) @@ERRORS
b) @@ERROR
c) @@ERR
d) None of the mentioned
View Answer

Answer: b
Explanation: @@ERROR is one of the basic error handling mechanisms in SQL Server.

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.