Home > Microsoft .Net Development Tips > Microsoft SQL Server > Use the firehose cursor
Win Development Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

MICROSOFT SQL SERVER

Use the firehose cursor


Barrie Sosinsky
08.13.2003
Rating: --- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


A cursor is an object that specifies a row within a set of data. Cursors let you move data within a set, update, and delete data.

SQL Server supports several types of cursors, but one read-only, non-scrollable cursor that is specially optimized for fast performance and worthy of note is the firehose cursor. You serve up the firehose cursor with a FAST_FORWARD command, for sequential access and forward traversal or your database records. The firehose cursor is the default cursor type for Recordset objects when that Recordset is defined with the Execute method for Command and Connection objects. The firehose mode refers to a connection that is maintained for as long as data can be returned. A server sends the data in a continuous stream, and does not wait for client requests using this kind of cursor. The reason that this cursor is fast is that it only requires data to be read, and there are no updates required by the cursor in its operation.

You can't always use a firehose cursor, even though you might want to. When you use a SELECT statement to define a cursor, if the statement contains a TOP clause and references to text, ntext, or image data, SQL server will substitute a keyset cursor in place of a firehose cursor. Also, when a SELECT statement defines a cursor using tables that contain triggers (Transact-SQL scripts) with ones that don't, SQL Server will substitute a static cursor in place of the firehose cursor. A static cursor is much slower than a firehose cursor; avoid it if possible.

With a firehose cursor you can add, delete, and update records for a FORWARD_ONLY cursor, provided you have a correct LockType. However this is not the case for a read-only cursor. You will not also be able to set a bookmark to the current row as well; nor can you use the Resync method should you wish to see the changes made to a recordset.

About the author

Barrie Sosinsky is president of consulting company Sosinsky and Associates (Medfield MA). He has written extensively on a variety of computer topics. His company specializes in custom software (database- and Web-related), training and technical documentation.

For More Information

  • Feedback: E-mail the editor with your thoughts about this tip.
  • More tips: Hundreds of free SQL Server tips and scripts.
  • Tip contest: Have a SQL Server tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize -- submit your tip today!
  • Ask the Experts: Our SQL, database design, Oracle, SQL Server, DB2, metadata, and data warehousing gurus are waiting to answer your toughest questions.
  • Forums: Ask your technical SQL Server questions--or help out your peers by answering them--in our active forums.
  • Best Web Links: SQL Server tips, tutorials, and scripts from around the Web.

Rate this Tip
To rate tips, you must be a member of SearchWinDevelopment.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
SQL Server and .NET development
Microsoft releases new CTP of Oslo SDK
Perpetuum unveils database synchronizer for .NET 2.0
The CTE, the hierarchical query and SQL Server 2005
SQL Server 2005 recursive functions and the CTE
SQL Examiner Suite synchronizes data schema, sets
Book excerpt: ADO.NET and SQL Server 2005
DataDirect database drivers now support MySQL
Top .NET tips of 2007 (so far)
Addressing common SQL Server questions
Book Excerpt: The .NET Framework and SQL Server 2005

Microsoft SQL Server
Using the Visual Studio 2005 DataSet Designer to build a data access layer
The CTE, the hierarchical query and SQL Server 2005
SQL Server 2005 recursive functions and the CTE
Choose the right .NET data provider, optimize application performance
The fallacy of the data layer -- or, a new architectural model for software designs
Book excerpt: ADO.NET and SQL Server 2005
Addressing common SQL Server questions
Book Excerpt: The .NET Framework and SQL Server 2005
WinForms development using SQL Server 2005 and Visual Basic 2005
Configuring ASP.NET 2.0 apps to SQL Server 2005 databases

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Database Programming Solutions - .NET XML, Visual Studio LINQ, ORM .NET
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts