October 2, 2014 at 3:08 pm
Hello,
I have this doubt. I've found different answers for this question in the web. A fast_forward cursor is read only by definition, meaning the rows can't be updated, but I'm not sure if they are insensitive or not. Do they reflect the changes in the database after the cursor is opened?
October 2, 2014 at 6:08 pm
I don't know; wish I could tell you. I'm replying to this post because no one else has.
Here's a great article by Itzek Ben Gan that will get you on the right track:
Sequential to Set-Based.:hehe:
-- Itzik Ben-Gan 2001
October 3, 2014 at 10:05 am
Yes, because the cursor is DYNAMIC, at least based on my reading of BOL:
"
DECLARE CURSOR
...
FORWARD_ONLY
...If FORWARD_ONLY is specified without the STATIC, KEYSET, or DYNAMIC keywords, the cursor operates as a DYNAMIC cursor. When neither FORWARD_ONLY nor SCROLL is specified, FORWARD_ONLY is the default, unless the keywords STATIC, KEYSET, or DYNAMIC are specified.
"
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
October 3, 2014 at 10:28 am
Code below appears to confirm that. Although I did notice that if you added "TOP (100)", it became a KEYSET cursor, even w/o you explicitly indicating that.
DECLARE csr1 CURSOR FORWARD_ONLY FOR
SELECT * --SELECT TOP (100) * ::= KEYSET cursor rather than DYNAMIC
FROM sys.objects
--OPEN csr1
DECLARE @cursor1 CURSOR
EXEC sp_cursor_list @cursor1 OUTPUT, 3
WHILE 1 = 1
BEGIN
FETCH NEXT FROM @cursor1
IF @@FETCH_STATUS <> 0
BREAK
END --WHILE
DEALLOCATE csr1
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
October 3, 2014 at 9:49 pm
gyerena (10/2/2014)
Hello,I have this doubt. I've found different answers for this question in the web. A fast_forward cursor is read only by definition, meaning the rows can't be updated, but I'm not sure if they are insensitive or not. Do they reflect the changes in the database after the cursor is opened?
The next question would be, "Why do you ask"? Are you planning on doing something with a cursor? If so, consider posting the problem and let's see if we can find a reasonable way around it.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 11, 2014 at 9:29 am
Thanks for your answer.
It was necessary to iterate through the data because there were several calls to stored procedures already developed (and there were call to other stored procedures inside these). However I saw the article you mentioned and it was useful. I found this article about how to substitute cursors for while cycles when it is necessary to iterate: http://www.codemag.com/Article/060113. This was really useful.
Regarding the original question I must say I have more doubts than before, because of some tests I did. I would post them later.
November 11, 2014 at 9:32 am
Alan.B (10/2/2014)
I don't know; wish I could tell you. I'm replying to this post because no one else has.Here's a great article by Itzek Ben Gan that will get you on the right track:
Sequential to Set-Based.:hehe:
Thanks for your answer.
It was necessary to iterate through the data because there were several calls to stored procedures already developed (and there were call to other stored procedures inside these). However I saw the article you mentioned and it was useful. I found this article about how to substitute cursors for while cycles when it is necessary to iterate: http://www.codemag.com/Article/060113. This was really useful.
Regarding the original question I must say I have more doubts than before, because of some tests I did. I would post them later.
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply