sp_describe_cursor_tables (Transact-SQL)

适用于:SQL Server

报告由服务器游标引用的对象或基表。

Transact-SQL 语法约定

语法

sp_describe_cursor_tables
    [ @cursor_return = ] cursor_return OUTPUT
    , [ @cursor_source = ] { N'local' | N'global' | N'variable' }
    , [ @cursor_identity = ] N'cursor_identity'
[ ; ]

参数

[ @cursor_return = ] cursor_return OUTPUT

要接收游标输出的声明游标变量的名称。 @cursor_return是一个 OUTPUT 游标,没有默认值,在调用时sp_describe_cursor_tables不得与任何游标关联。 返回的游标是可滚动的动态只读游标。

[ @cursor_source = ] { N'local' |N'global' |N'variable' }

指定使用以下哪一名称来指定所报告的游标:本地游标、全局游标或游标变量的名称。 @cursor_source为 nvarchar(30),没有默认值。

[ @cursor_identity = ] N'cursor_identity'

当@cursor_source为时,@cursor_identity是由语句创建的DECLARE CURSOR游标的名称,要么具有LOCAL关键字 (keyword),要么默认为LOCAL该游标。local

当@cursor_source为时,@cursor_identity是由语句创建的DECLARE CURSOR游标的名称,要么具有GLOBAL关键字 (keyword),要么默认为GLOBAL该游标。global @cursor_identity也可以是 ODBC 应用程序打开的 API 服务器游标的名称,然后通过调用SQLSetCursorName来命名游标。

@cursor_sourcevariable@cursor_identity 是与打开游标关联的游标变量的名称。

@cursor_identity为 nvarchar(128),没有默认值。

返回代码值

无。

返回的游标

sp_describe_cursor_tables 将其报表封装为 Transact-SQL 游标 输出参数。 这样,Transact-SQL 批处理、存储过程和触发器就可以一次处理一行输出。 这也意味着无法直接从 API 函数调用该过程。 游标输出参数必须绑定到程序变量,但 API 不支持绑定游标参数或变量。

下表显示了游标的格式,该游标由 sp_describe_cursor_tables.

列名称 数据类型 描述
table_owner sysname 表所有者的用户 ID。
table_name sysname 对象或基表的名称。 在 SQL Server 中,服务器游标始终返回用户指定的对象,而不是基表。
optimizer_hint smallint 由以下一个或多个选项组成的位图:

1 = 行级锁定 (ROWLOCK
4 = 页面级锁定 (PAGELOCK
8 = 表锁 (TABLOCK
16 = 排他表锁 (TABLOCKX
32 = 更新锁 (UPDLOCK
64 = 无锁 (NOLOCK
128 = 快速第一行选项 (FASTFIRST
4096 = 与 (HOLDLOCK) 一起使用DECLARE CURSOR时读取可重复语义

如果提供多个选项,系统将使用限制性最高的选项。 但是, sp_describe_cursor_tables 显示查询中指定的标志。
lock_type smallint 为该游标的每个基表显式或隐式地请求的滚动锁类型。 该值可以是以下选项之一:

0 = 无
1 = 共享
3 = 更新
server_name sysname,可为 null 驻留表的链接服务器的名称。 NULL使用时间或OPENROWSET使用时间OPENQUERY
objectid int 表的对象 ID。 0 何时 OPENQUERY 使用或 OPENROWSET 使用。
dbid int 表所在的数据库的 ID。0 何时 OPENQUERY 使用或 OPENROWSET 使用。
dbname sysname可为 null 表所在的数据库的名称。 NULL使用时间或OPENROWSET使用时间OPENQUERY

注解

sp_describe_cursor_tables 描述服务器游标引用的基表。 有关游标返回的结果集属性的说明,请使用 sp_describe_cursor_columns。 有关游标的全局特征的说明,例如其可滚动性和可更新性,请使用 sp_describe_cursor。 若要获取在连接上可见的 Transact-SQL Server 游标的报表,请使用 sp_cursor_list

权限

要求 公共 角色具有成员身份。

示例

下面的示例打开一个全局游标,用于 sp_describe_cursor_tables 报告游标引用的表。

USE AdventureWorks2022;
GO
-- Declare and open a global cursor.
DECLARE abc CURSOR KEYSET FOR
SELECT LastName
FROM Person.Person
WHERE LastName LIKE 'S%';

OPEN abc;
GO
-- Declare a cursor variable to hold the cursor output variable
-- from sp_describe_cursor_tables.
DECLARE @Report CURSOR;

-- Execute sp_describe_cursor_tables into the cursor variable.
EXEC master.dbo.sp_describe_cursor_tables
    @cursor_return = @Report OUTPUT,
    @cursor_source = N'global',
    @cursor_identity = N'abc';

-- Fetch all the rows from the sp_describe_cursor_tables output cursor.
FETCH NEXT from @Report;
WHILE (@@FETCH_STATUS <> -1)
BEGIN
   FETCH NEXT from @Report;
END

-- Close and deallocate the cursor from sp_describe_cursor_tables.
CLOSE @Report;
DEALLOCATE @Report;
GO

-- Close and deallocate the original cursor.
CLOSE abc;
DEALLOCATE abc;
GO