This set of SQL Server Multiple Choice Questions & Answers (MCQs) focuses on “Cursor”.
1. Life cycle of typical cursor involves ______ steps in SQL Server.
a) 2
b) 3
c) 4
d) 5
View Answer
Explanation: The five steps are Declare Cursor,Open,fetch,CLose and Deallocate.
2. Point out the correct statement.
a) A Cursor is opened and populated by executing the SQL statement defined by the cursor
b) After data manipulation, we should close the cursor explicitly
c) A cursor is declared by defining the SQL statement that returns a result set
d) All of the mentioned
View Answer
Explanation: We use cursor when we need to update records in a database table in singleton fashion means row by row.
3. How many type of cursor is present in SQL Server?
a) 3
b) 4
c) 5
d) 6
View Answer
Explanation: SQL Server supports four types of cursor.
4. Various alternatives to cursor in SQL Server are ___________
a) FOR
b) IF..ELSE
c) WHILE
d) All of the mentioned
View Answer
Explanation: Cursor alternatives are WHILE loop, subqueries, Temporary tables and Table variables.
5. Point out the wrong statement.
a) We should use cursor in all cases
b) A static cursor can move forward and backward direction
c) A forward only cursor is the fastest cursor
d) All of the mentioned
View Answer
Explanation: We should use cursor in that case when there is no option except cursor.
6. A dynamic cursor in SQL Server allows you to see __________ data.
a) Updated
b) Inserted
c) Deleted
d) All of the mentioned
View Answer
Explanation: A dynamic cursor allows you to see the data updation, deletion and insertion in the data source while the cursor is open.
7. Which of the cursors further have their subtypes?
a) Static Cursors
b) Dynamic Cursors
c) Keyset Driven Cursors
d) None of the mentioned
View Answer
Explanation: There are three more types of Forward Only Cursors in SQL Server.
8. Which of the following FORWARD ONLY Cursor is populated at the time of creation?
a) KEYSET
b) FORWARD_ONLY STATIC
c) FAST_FORWARD
d) All of the mentioned
View Answer
Explanation: A FORWARD_ONLY STATIC Cursor is populated at the time of creation and cached the data to the cursor lifetime. It is not sensitive to any changes to the data source.
9. ____________ cursor is sensitive to any changes to the data source.
a) Static Cursors
b) Dynamic Cursors
c) Keyset Driven Cursors
d) None of the mentioned
View Answer
Explanation: A keyset driven cursor is sensitive to any changes to the data source and supports update, delete operations.
10. SQL Server static cursors are always ___________
a) Read-only
b) Write-only
c) Read, Write
d) None of the mentioned
View Answer
Explanation: A static cursor populates the result set at the time of cursor creation and query result is cached for the lifetime of the cursor.
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
- Check Information Technology Books
- Practice Programming MCQs
- Check SQL Server Books