1.

What Is A Cursor And What Are Its Different Types?

Answer»

This is the frequently asked SQL Server Interview Questions in an interview. A cursor is a database object, which can utilize to retrieve the data, one row at a time from the result set. When data NEEDS to be updated row-by-row, cursors can be very HANDY. The cursor life cycle consists of mainly 5 STEPS.

  • Declaring cursor – declared by defining SQL statement.
  • Opening cursor – Opened for storing data, retrieved from the result set.
  • Fetching cursor – Once a cursor is opened, rows can be FETCHED one by one or in a block to perform data manipulation.
  • Closing cursor – Once data manipulation is done, cursor needs to be closed explicitly.
  • Deal location cursor – to delete cursor definition, cursors should be DEALLOCATED, released all system resources associated with a cursor.

Types of a cursor are:

  • Static – These types of a cursor are responsible for making a temporary copy of data and store in TempDB. Any modification done on base table is not highlighted in data return by fetches made by a cursor.
  • Dynamic – As the opposite of static, they highlight all changes in a base table.
  • Forward-only – cursor can only fetch sequentially from first to last.
  • Keyset-driven – Keyset is the set of keys which uniquely identifies a row is built in TempDB.

This is the frequently asked SQL Server Interview Questions in an interview. A cursor is a database object, which can utilize to retrieve the data, one row at a time from the result set. When data needs to be updated row-by-row, cursors can be very handy. The cursor life cycle consists of mainly 5 steps.

Types of a cursor are:



Discussion

No Comment Found