Chapter 8. Cursors

Itzik Ben-Gan

A cursor is a programmatic construct in T-SQL. It represents a result set of a query that you can iterate through one row at a time, possibly in a predetermined order. Programmers who are used to procedural programming but are not yet experienced with SQL tend to use cursors a lot because using cursors feels like an extension of what they already know. However, you should be aware of the implications of using cursors. Using cursors is not in accord with the relational model, which deals with whole sets, as opposed to dealing with individual rows. By using cursors, you pretty much go against the model. Also, in terms of the work done by the Microsoft SQL Server engine, the processing of each cursor row incurs an ...

Get Inside Microsoft® SQL Server® 2008: T-SQL Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.