thinQmaster Virtual testing partner Adaptive practice exams that find your weak spots and drill them. Every answer explained. From $69
Enroll

thinQmaster

Find your exam

Five questions free, before you decide.

Step 1 · choose a vendor

In one of our camps? Your practice exams come with the tuition — they are on your study page already.

Data & Analytics · Advanced

Cursor

A database object that lets procedural code process a query result one row at a time.

Definition

Cursors declare a query, open it, fetch rows in a loop and close it. They are sometimes needed for row-specific procedural logic but are usually far slower than set-based SQL, which processes whole sets in one statement.

Example

DECLARE c CURSOR FOR SELECT ID FROM Queue; OPEN c; FETCH NEXT FROM c INTO @id;

Exam tip

When asked to improve performance of row-by-row cursor logic, the expected answer is to rewrite it as set-based SQL.

Related terms