Recall & Review
beginner
What is a cursor in MySQL?
A cursor is a database object used to retrieve and process rows one at a time from a result set, allowing row-by-row operations.
Click to reveal answer
beginner
List the main steps to use a cursor in MySQL.
1. Declare the cursor with a SELECT statement.<br>2. Open the cursor.<br>3. Fetch rows one by one.<br>4. Close the cursor when done.
Click to reveal answer
beginner
Why do we need to close a cursor in MySQL?
Closing a cursor releases the memory and resources it uses. Not closing it can cause resource leaks and slow down the database.
Click to reveal answer
intermediate
What happens if you fetch from a cursor but no more rows are available?
MySQL raises the NOT FOUND condition, indicating there are no more rows to fetch.
Click to reveal answer
intermediate
Can you use a cursor to update rows while iterating in MySQL?
Yes, you can fetch rows with a cursor and then use UPDATE statements to modify those rows inside the loop.
Click to reveal answer
What is the first step when using a cursor in MySQL?
✗ Incorrect
You must declare the cursor first with a SELECT statement before opening or fetching.
Which statement correctly closes a cursor named 'cur'?
✗ Incorrect
The correct syntax to close a cursor is CLOSE followed by the cursor name.
What condition indicates no more rows are available when fetching from a cursor?
✗ Incorrect
MySQL uses the NOT FOUND condition to signal no more rows to fetch.
Can you fetch multiple rows at once using a cursor in MySQL?
✗ Incorrect
Cursors are designed to fetch rows one by one for row-by-row processing.
What happens if you forget to close a cursor?
✗ Incorrect
Not closing a cursor keeps resources allocated, which can slow down the database.
Explain how to use a cursor in MySQL to process rows one by one.
Think about the sequence of steps to handle each row individually.
You got /5 concepts.
Describe why cursors are useful and when you might use them.
Consider situations where you need to do something special with each row.
You got /4 concepts.