Answers

Question and Answer:

  Home  MS SQL Server

⟩ How To Create a Dynamic Cursor with the DYNAMIC Option?

If the underlying table is changed after the cursor is opened, should the changes be reflected in the cursor result set? The answer is based on the update option used when creating the cursor. SQL SERVER supports two update options:

1. STATIC - The result set will be a static copy created when the OPEN statement is executed. Subsequent updates on the underlying tables will not affect the result set. STATIC is the default option.

2. SCROLL - The result set will be dynamically updated each time when a FETCH statement is executed. In another word, the result set always reflects the latest changes on the underlying tables.

The tutorial script below gives you a good example of how dynamic cursors work:

USE GlobalGuideLineDatabase;

GO

DECLARE @ggl_cursor CURSOR;

SET @ggl_cursor = CURSOR FOR

SELECT id, url, notes, counts, time FROM ggl_links;

OPEN @ggl_cursor;

DECLARE @id INT, @url VARCHAR(80), @notes VARCHAR(80),

@counts INT, @time DATETIME;

FETCH NEXT FROM @ggl_cursor INTO @id, @url, @notes,

@counts, @time;

 141 views

More Questions for you: