IT tutorials
 
Database
 

SQL Server 2012 : Configuration Options (part 9) - Cursor-Configuration Properties

1/11/2014 8:46:22 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

9. Cursor-Configuration Properties

The cursor-configuration properties, as shown in Table 8, are used to control cursor behavior in SQL Server.

Table 8 Cursor-Configuration Properties

c19tnt008

Tip
To view information about the open cursors in various databases, query the sys.dm_exec_cursors dynamic management view.

Cursor Threshold

The cursor threshold property sets the number of rows in a cursor set before the cursor keysets are asynchronously generated. The query optimizer estimates the number of rows that will be returned from the result set. If the estimated number of rows is greater than the cursor threshold, then the cursor is asynchronously generated; if it is synchronously generated causing a delay, the query must wait until all rows are fetched. Every cursor keyset will be asynchronously generated if the cursor threshold property is set to 0.

The default of -1 causes all keysets to be synchronously generated, which is okay for smaller keysets. For larger cursor keysets, though, this may be a problem.

In Management Studio, you can set the cursor threshold option to the wanted value in the “Cursor Threshold box on the Server Properties Advanced tab (refer to Figure 6).

When you work with cursors, the following code permits synchronous cursor keysets for cursors of up to 10,000 rows:

EXEC sp_configure ‘show advanced options', 1; 
RECONFIGURE;
EXEC sp_configure ‘cursor threshold', 10000;
RECONFIGURE;

Cursor Close on Commit

The cursor close on commit property closes an open cursor after a transaction is committed when set to on. If it is set to off (default), then cursors remain open across transactions until a close cursor statement is issued.

The cursor close on commit option can be set from Management Studio and code at server, database, and connection level. In Management Studio, the cursor close on commit option can be turned on at the following level:

  • Server level: Checks the Cursor Close on Commit check box on the Server properties Connections tab (refer to Figure 5).
  • Database level: Selects True for the Close Cursor on Commit Enabled box on the Database Properties Options tab .
  • Connection level: To set this property for current queries, click the Query menu ? Query Options ? Execution ? ANSI, and check the Set Cursor Close on Commit check box. To set this property for all future connections, click the Tools menu ? Options ? Query Execution ? ANSI, and check Set Cursor Close on Commit check box

To set cursor close on commit in code, do the following:

  • Server level: Sets the option on for the server:
EXEC sp_configure ‘user options', 4;
RECONFIGURE;
  • Database level: Sets the option on for the AdventureWorks2012 sample database:
ALTER DATABASE AdventureWorks2012 SET CURSOR_CLOSE_ON_COMMIT ON;
  • Connection level: Sets the option on for the current connection:
SET CURSOR_CLOSE_ON_COMMIT ON; 

Cursor Default

This property makes each cursor local to the object that declared it when set to local. When it is set to global (default), the scope of the cursor can be extended outside the object that created it.

In Management Studio, you can set the cursor default option to the wanted scope in the Default Cursor box on the Database Properties Options tab .To set the cursor default for the AdventureWorks2012 sample database to LOCAL in code, do the following:

ALTER DATABASE AdventureWorks2012 SET CURSOR_DEFAULT LOCAL;
 
Others
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us