I am new to database concepts and I found some sources that try to explain what is a cursor, but I can't understand what they mean. Can someone explain in a very basic manner what a cursor is and what it does inside a database so that a rookie may be able to understand?
Thanks, guys.
A “cursor”
cursorsdatabase-agnosticterminology
Related Question
- T-SQL – Compare Previous Non-NULL and Current Row Using CTE
- SQL Server – Cursor Performance on New Server
- SQL Server sp_cursoropen and Parallelism – Performance Implications
- MongoDB Log Analysis – Understanding ‘killcursors: found 0 of 1’ with ReplicaSet
- SQL Server Performance – sp_cursorprepexec Causing High Reads
Best Answer
A cursor is essentially a materialized result set from a query that maintains its own state (essentially remembers what row is "current") and in some cases allows you to manipulate the current row.
Cursor lifecycle looks more or less like this:
Typically steps 2-4 are performed in an application program (or stored procedure) loop, allowing you to read each record of the result set and do something with it if necessary.