Reviewed by Aditya Kumar · Last reviewed 2026-03-24
**Architectural Logic**: Cursors = row-at-a-time; stored procedures = encapsulated logic. **Cursors**: Iterate result set row-by-row; use for per-row logic that can't be expressed set-based. Expensive—O(n) round-trips; avoid for bulk ETL. **Stored Procedures**: Reusable SQL;...
Architectural Logic: Cursors = row-at-a-time; stored procedures = encapsulated logic. Cursors: Iterate result set row-by-row; use for per-row logic that can't be expressed set-based. Expensive—O(n) round-trips; avoid for bulk ETL. Stored Procedures: Reusable SQL; reduce network round-trips; enforce business rules; parameterized. Why Avoid Cursors: Set-based operations are 10-100x faster; cursors block connections. Use Cases: Cursors—rare, complex per-row decisions; procedures—audit trails, validation, scheduled jobs. Scalability: Procedures scale; cursors don't. Modern Alternative: Use application-layer loops with batch SQL; or Spark for bulk processing.
Red Flag: Using cursors for bulk upsert—instant red flag. Pro-Move: Rewrite as MERGE or batch UPDATE with temp table; reference performance improvement (e.g., 2hrs → 5min).
According to DataEngPrep.tech, this is one of the most frequently asked SQL interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.