none
STATIC CURSOR RRS feed

  • Question

  • Hi,

      In MSDN help file I read about static cursor

    STATIC

    Defines a cursor that makes a temporary copy of the data to be used by the cursor. All requests to the cursor are answered from this temporary table in tempdb; therefore, modifications made to base tables are not reflected in the data returned by fetches made to this cursor, and this cursor does not allow modifications

    It say's that modifications is not allowed in the static cursor.

    I have a  questions regarding that

    question :

    Static Cursor

    declare ll cursor global static
                for select  name, salary from ag
      open ll
                 fetch from ll
     
                  while @@FETCH_STATUS=0
                   fetch from ll
                    update ag set salary=200 where 1=1
     
       close ll
    deallocate ll

    In "AG" table, "SALARY" was 100 for all the entries.

    When I run the Cursor, it showed the salary value as "100" correctly.

    After the cursor was closed, I run the query select * from AG.

    But the result had updated to salary 200 as given in the cursor.

    Help file says  modifications is not allowed in the static cursor. But I am able to update the data using static cursor.

     

    Wednesday, August 12, 2015 9:58 AM

Answers

All replies