INSENSITIVE
Example
Section titled “Example”DECLARE cur1 CURSORINSENSITIVE FORSELECT customerNameFROM Customers;Output
Section titled “Output”+------------------+| customerName |+------------------+| Atelier graphique|| Signal Gift Stores|| Australian Collectors, Co.|| ... |+------------------+Explanation
Section titled “Explanation”In this example, the keyword INSENSITIVE is used while declaring a cursor. It is used to create a temporary copy of the data retrieved by the cursor so that changes made to the database data cannot affect the cursor results. The query within the cursor is fetching the customerName from the Customers table.
Example
Section titled “Example”CREATE PROCEDURE GetOrderSummary ASBEGINDECLARE @Order_Cursor INSENSITIVE CURSOR FORSELECT OrderID, CustomerID, OrderDateFROM Orders
OPEN @Order_Cursor
DECLARE @OrderID int, @CustomerID varchar(10), @OrderDate datetimeFETCH NEXT FROM @Order_Cursor INTO @OrderID, @CustomerID, @OrderDateWHILE @@FETCH_STATUS = 0BEGINPRINT 'Order ID: ' + CAST(@OrderID AS VARCHAR)PRINT 'Customer ID: ' + @CustomerIDPRINT 'Order Date: ' + CONVERT(VARCHAR, @OrderDate, 101)FETCH NEXT FROM @Order_Cursor INTO @OrderID, @CustomerID, @OrderDateEND
CLOSE @Order_CursorDEALLOCATE @Order_CursorENDOutput
Section titled “Output”Order ID: 10248Customer ID: VINETOrder Date: 07/04/1996
Order ID: 10249Customer ID: TOMSPOrder Date: 07/05/1996...Explanation
Section titled “Explanation”Here, an INSENSITIVE cursor is utilized to retrieve every order from the Orders table. The data is fetched from the cursor using a WHILE loop. The key aspect is that this INSENSITIVE cursor displays the data as it was when the cursor opened, meaning modifications to the table during the cursor’s lifetime are not reflected in the data presented by the cursor.