SQL Server Cursor Types - KEYSET Cursor | SQL Server Tutorial / TSQL Tutorial

Veröffentlicht am: 12 April 2015
auf dem Kanal: TechBrothersIT
4,952
22

When we open Keyset Cursor the membership and order of rows in the cursor is fixed. KeySet Cursor create a temp table in TempDB with uniquely built values from the columns which we use in Select statement.

Here are important points to remember about KEYSET Cursor in SQL Server

If your Select query is using any table without Unique Index, the KEYSET cursor is simply going to be converted to Static Cursor. Make sure all of the tables you are using in Select Query has unique index. This is important as KEYSET Cursor build unique identifiers for the rows by using these unique values.
If we insert the rows in source table/s once the cursor is open. Those Inserts will not be visible in already opened cursor.
If we make update to nonkey values in the base tables, those changes will be visible in cursor.
If you update the Key column value in Base Table/s while the cursor is opened and then try to fetch the value. @@FETCH_STATUS will return you -2. The updated made inside the cursor to Key Column with WHERE CURRENT OF clause will be visible at the end of Cursor.
If you delete the row from Base Table/s while the cursor is open and then try to fetch that row in cursor, @@FETCH_STATUS will return -2.
KEYSET cursors are scrollable.

Blog post link for the video with scripts
http://sqlage.blogspot.com/2015/04/sq...


Auf dieser Seite können Sie das Online-Video SQL Server Cursor Types - KEYSET Cursor | SQL Server Tutorial / TSQL Tutorial mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer TechBrothersIT 12 April 2015 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 4,952 Mal angesehen und es wurde von 22 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!