0
0
MySQLquery~5 mins

Cursors for row iteration in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AOpen the cursor
BDeclare the cursor
CFetch a row
DClose the cursor
Which statement correctly closes a cursor named 'cur'?
ACLOSE cur;
BEND cur;
CSTOP cur;
DFINISH cur;
What condition indicates no more rows are available when fetching from a cursor?
AEMPTY
BNO ROWS
CEND OF DATA
DNOT FOUND
Can you fetch multiple rows at once using a cursor in MySQL?
ANo, cursors fetch one row at a time
BYes, cursors fetch all rows at once
CYes, but only two rows at a time
DOnly if you use a special option
What happens if you forget to close a cursor?
ANothing, it is safe to leave open
BThe cursor automatically closes after fetching
CResources remain allocated, causing potential issues
DThe database crashes
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.