# Cursor

Steps through query results one row at a time; usually a last resort.

## What is **Cursor**?

A **cursor** walks through query results one row at a time. It is slow compared to set-based SQL, so use it only when you truly must handle rows one by one.

```sql
DECLARE @name NVARCHAR(100);
DECLARE customers CURSOR FAST_FORWARD FOR SELECT Name FROM dbo.Customers;
OPEN customers;
FETCH NEXT FROM customers INTO @name;
WHILE @@FETCH_STATUS = 0
BEGIN
    PRINT @name;
    FETCH NEXT FROM customers INTO @name;
END
CLOSE customers; DEALLOCATE customers;
```

Level: Freelancer · [More Database terms at this level](https://www.ask-codey.com/glossary/subjects/database/freelancer)

Updated: September 27, 2026

Source: https://www.ask-codey.com/glossary/cursor
