Every cursor uses temporary resources to hold its data. These resources can be memory, a disk paging file, temporary disk files, or even temporary storage in the database. The cursor is called a client-side cursor when these resources are located on the client machine. The cursor is called a server-side cursor when these resources are located on the server machine.
Client-Side Cursors
With a non-keyset client-side cursor, the server sends the entire result set across the network to the client machine. The client machine provides and manages the temporary resources needed by the cursor and result set. The client-side application can browse through the entire result set to determine which rows it requires.
Static and keyset-driven client-side cursors may place a significant load on your workstation if they include too many rows. While all of the cursor libraries are capable of building cursors with thousands of rows, applications designed to fetch such large rowsets may perform poorly. There are exceptions, of course. For some applications, a large client-side cursor may be perfectly appropriate and performance may not be an issue.
One obvious benefit of the client-side cursor is quick response. After the result set has been downloaded to the client machine, browsing through the rows is very fast. Your application is generally more scalable with client-side cursors because the cursor's resource requirements are placed on each separate client and not on the server.
Server-Side Cursors
With a server-side cursor, the server manages the result set using resources provided by the server machine. The server-side cursor returns only the requested data over the network. This type of cursor can sometimes provide better performance than the client-side cursor, especially in situations where excessive network traffic is a problem.
Server-side cursors also permit more than one operation on the connection. That is, once you create the cursor, you can use the same connection to make changes to the rows — without having to establish an additional connection to handle the underlying update queries.
However, it's important to point out that a server-side cursor is — at least temporarily — consuming precious server resources for every active client. You must plan accordingly to ensure that your server hardware is capable of managing all of the server-side cursors requested by active clients. Also, a server-side cursor can be slow because it provides only single row access — there is no batch cursor available.
Server-side cursors are useful when inserting, updating, or deleting records. With server-side cursors, you can have multiple active statements on the same connection. With SQL Server, you can have pending results in multiple statement handles.
Advantages to using server-side cursors include those in the following list.
-
Memory usage The client does not need to cache large amounts of data or maintain information about the cursor position because the server is doing that.
-
Performance If you are going to access only some of the data in the result set, or access the data just a few times, a server-side cursor minimizes network traffic.
-
Additional cursor types With server-side cursors, both keyset and dynamic cursors are available.
-
Positioned updates Server-side cursors support direct positioned updates, whereas ODBC simulates positioned cursor updates by generating an SQL search and update statement. Direct positioned updates are not only faster, they avoid the risk of unintended update collisions.
Notice that server-side cursors do not support the execution of queries that return more than one result set. However, it is possible to use the server-side cursor library with this type of query if you request a forward-only, read-only cursor with a rowset size of 1. Basically, this set of options disables the scrolling overhead associated with the cursor and enables the cursor driver to manage each result set individually.
分享到:
相关推荐
重点介绍了几种关键的技术手段:服务器端游标、客户端游标、操作查询以及存储过程。并通过具体实例展示了这些技术的应用场景。 #### 关键词 - 服务器端游标 - 客户端游标 - 操作查询 - 存储过程 #### 中图分类号 -...
在Oracle中,游标有两种类型:前端游标(客户端游标)和后端游标(服务器游标)。前端游标通常由数据库客户端工具处理,而后端游标则由数据库服务器管理。使用游标时,通常需要经历以下四个步骤: 1. **定义游标**...
3. 客户端游标:在客户端缓存整个结果集,常用于静态游标,当服务器游标功能不足时使用。 游标的操作通常包含四个步骤: 1. 声明游标:定义游标名和相关的SQL查询语句,例如`DECLARE CustomerCursor CURSOR FOR ...
游标提供了一种从表中检索数据并进行操作的灵活手段,主要用在服务器上,处理由客户端发送给服务器端的 SQL 语句,或是批处理、存储过程、触发器中的数据处理请求。 1. 游标的概念 游标的优点在于它可以定位到结果...
它们在服务器端管理,不支持批量数据提取。API游标则与OLE DB、ODBC和DB_library接口配合使用,每次客户端调用API游标函数,请求都会传递给服务器处理。客户游标则在客户端缓存结果集,主要用于静态游标,常作为...
- **应用场景**:主要用于服务器端的数据处理,可以通过客户端发送的SQL语句或存储过程进行管理。 - **特点**:不支持提取数据块或多行数据。 ##### 3.2 API游标 - **定义**:虽然MySQL没有直接支持API游标这一概念...
API服务器游标和Transaction-SQL游标在服务器端运行,也称为服务器游标。API服务器游标通过API函数管理,支持打开连接、设置游标属性、执行SQL语句和提取数据行。它们包括静态游标、动态游标、只进游标和键集驱动...
- API 服务器游标:这类游标在服务器端运行,包括静态游标、动态游标、只进游标和键集驱动游标。 - 静态游标:一次性加载所有结果到内存,不反映数据的实时变化,只读且不显示新插入的行。 - 动态游标:实时反映...
1. Transact-SQL 游标:通过`DECLARE CURSOR`语法定义,主要用于T-SQL脚本、存储过程和触发器,主要在服务器端管理,不支持数据块提取。 2. API 游标:适用于OLE DB、ODBC和DB_library,每次客户端调用API函数时,...
这种游标在服务器端处理,不支持批量数据提取。 2. API 游标:适用于OLE DB、ODBC和DB_library接口,处理发生在服务器上。API调用会被传递到服务器来管理游标操作。 3. 客户游标:在客户端缓存整个结果集,通常用于...
1. **定义**:在Oracle中,游标是一种服务器端的工作区,用来保存SELECT语句的结果集。当执行一个查询时,如果结果集很大,将其全部加载到内存中可能会非常低效甚至不可能。因此,Oracle通过游标将结果集分块加载到...
- **减少网络流量**:存储过程可以在服务器端执行,减少了客户端与服务器之间的数据传输。 - **易于管理**:可以集中管理数据库逻辑。 **3.2 创建存储过程** 创建存储过程的基本语法为: ```sql CREATE PROCEDURE...
而客户端游标则被称为前台游标。 游标使用的基本步骤包括声明游标、打开游标、提取游标和关闭游标。 1. 声明游标:使用DECLARE CURSOR语句来创建游标。可以通过设定游标的作用域、移动方向和访问属性来定义游标。...
游标机制使得数据能够在客户端(应用程序)和服务器端(数据库)之间双向传输。 - **从数据库中获取数据**:使用`SELECT`语句将数据取到应用程序空间。 - **向数据库中插入数据**:使用`INSERT`语句将数据从应用...
它们在服务器端管理,不支持批量数据处理。 2. **API游标**:在OLE DB、ODBC或DB_library中使用,每次客户端应用调用API函数时,请求会被传递到服务器进行处理。适用于服务器上的应用。 3. **客户游标**:在客户端...
数据库服务器端编程主要涉及到在数据库管理系统中实现更高级别的逻辑处理和数据操作,这通常包括存储过程、触发器和游标等技术。这些技术能够提高系统的效率,增强安全性,并简化复杂的数据库操作。 **1. 存储过程*...
11. CursorLocation 属性:该属性决定时使用服务器端游标还是客户端游标(使用哪个游标引擎)。取值为:2(服务器端游标)、3(客户端游标)。 12. CursorType 属性:该属性设置用于下一级 recordset 的游标类型。...
存储过程是预编译的SQL语句集合,可以在数据库服务器端执行。在Java中,可以使用`CallableStatement`来调用存储过程,特别是处理返回输出游标的存储过程。游标允许我们逐行处理结果集。以下是一个调用返回游标的...