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
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
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
Explanation: DML statements can be checked for handling errors.
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
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
Explanation: A TRY…CATCH construct catches all execution errors that have a severity higher than 10 that do not close the database connection.
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
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
Explanation: Generates an error message and initiates error processing for the session.
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
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
Explanation: ERROR_SEVERITY() returns the severity level of the error.
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
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.
- Apply for Programming Internship
- Practice Programming MCQs
- Check SQL Server Books
- Check Information Technology Books