Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Cursors: Static v Insensitive Expand / Collapse
Author
Message
Posted Friday, August 12, 2011 3:26 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, June 12, 2014 5:18 AM
Points: 14, Visits: 57
Could anyone explain the difference between a static and insensitive cursor? On the face of it they seem very similar. Both copy the result set to tempdb and operate on that rather than on the underlying table, and both prohibit the modification to data.
Post #1159056
Posted Friday, August 12, 2011 7:21 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:48 PM
Points: 13,427, Visits: 12,292
I think the more important question is how can you eliminate your cursor and therefore not really care about some of the subtle details.

Honestly cursors are one the most resource intensive (and SLOW) methods of data manipulation available in sql server. There are a few very rare cases where a cursor is the only way to accomplish something. For everything else there is a much faster set based way of handling things.

If you really want to know the details about your question it can be answered here.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1159186
Posted Friday, August 12, 2011 11:18 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, September 10, 2014 12:04 PM
Points: 7,203, Visits: 6,347
You're correct. The definition in BOL is pretty much identical, word for word, except for a final statement in the Insensitive part:


When ISO syntax is used, if INSENSITIVE is omitted, committed deletes and updates made to the underlying tables (by any user) are reflected in subsequent fetches.


I'm assuming this means one of two things. Either 1) STATIC can't be used with ISO Syntax or 2) if ISO Syntax is used with STATIC, it doesn't matter, you still don't get changed data with subsequent fetches.

But I'm guessing.


Brandie Tarvin, MCITP Database Administrator

Webpage: http://www.BrandieTarvin.net
LiveJournal Blog: http://brandietarvin.livejournal.com/
On LinkedIn!, Google+, and Twitter.

Freelance Writer: Shadowrun
Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Post #1159417
Posted Friday, August 12, 2011 1:38 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, August 21, 2014 9:40 AM
Points: 985, Visits: 1,326
Sean Lange (8/12/2011)
I think the more important question is how can you eliminate your cursor and therefore not really care about some of the subtle details.

Honestly cursors are one the most resource intensive (and SLOW) methods of data manipulation available in sql server. There are a few very rare cases where a cursor is the only way to accomplish something. For everything else there is a much faster set based way of handling things.

If you really want to know the details about your question it can be answered here.


I agree with you about 99%. There are situations where I HAVE to use a cursor, especially when producing a result set that has to be passed through a stored procedure call. Keep in mind this is done as a one-off data manipulation process and not used in mainstream production transaction processing. It is certainly easier than having to strip out the code from the sproc and put it into the remaining logic. Yes, in the long run it'd be faster but for a one-off, it isn't worth the extra time and effort

I have found CTEs & the MERGE constructs to be quite handy....

Kurt


Kurt W. Zimmerman
SR DBA
Lefrak Organization
New York, NY

http://www.linkedin.com/in/kurtwzimmerman
Post #1159502
Posted Friday, August 12, 2011 1:50 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:48 PM
Points: 13,427, Visits: 12,292
Kurt W. Zimmerman (8/12/2011)
Sean Lange (8/12/2011)
I think the more important question is how can you eliminate your cursor and therefore not really care about some of the subtle details.

Honestly cursors are one the most resource intensive (and SLOW) methods of data manipulation available in sql server. There are a few very rare cases where a cursor is the only way to accomplish something. For everything else there is a much faster set based way of handling things.

If you really want to know the details about your question it can be answered here.


I agree with you about 99%. There are situations where I HAVE to use a cursor, especially when producing a result set that has to be passed through a stored procedure call. Keep in mind this is done as a one-off data manipulation process and not used in mainstream production transaction processing. It is certainly easier than having to strip out the code from the sproc and put it into the remaining logic. Yes, in the long run it'd be faster but for a one-off, it isn't worth the extra time and effort

I have found CTEs & the MERGE constructs to be quite handy....

Kurt


Yes, that is exactly why I said "There are a few very rare cases where a cursor is the only way to accomplish something.".

As with everything in sql server there are no absolutes. "It depends" is still the only unchanging answer.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1159513
Posted Wednesday, August 17, 2011 2:15 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, June 12, 2014 5:18 AM
Points: 14, Visits: 57
Thanks to everyone for taking the time to read my post and reply.

I agree with what has been said about cursors being a last resort and that there are better alternatives in most cases.

I was really just asking the question out of interest, in that it seems strange to have two cursor types that, from their description on MSDN, appear to be nearly identical.
Post #1160986
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse