Share via


sp_describe_cursor_tables (Transact-SQL)

報告伺服器資料指標所參考的物件或基底資料表。

主題連結圖示Transact-SQL 語法慣例

語法

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

引數

  • [ @cursor_return = ] output_cursor_variableOUTPUT
    這是用來接收資料指標輸出之已宣告資料指標變數的名稱。output_cursor_variable 是 cursor,沒有預設值,而且在呼叫 sp_describe_cursor_tables 時,不能與任何資料指標有關聯。傳回的資料指標是一個可捲動的動態唯讀資料指標。

  • [ @cursor_source = ] { N'local' | N'global' | N'variable' }
    指定要報告的資料指標是利用本機資料指標、全域資料指標或資料指標變數的名稱來指定。參數是 nvarchar(30)。

  • [ @cursor_identity = ] N'local_cursor_name'
    這是可能含有 LOCAL 關鍵字或預設為 LOCAL 的 DECLARE CURSOR 陳述式所建立之資料指標的名稱。local_cursor_name 是 nvarchar(128)。

  • [ @cursor_identity = ] N'global_cursor_name'
    這是可能含有 GLOBAL 關鍵字或預設為 GLOBAL 的 DECLARE CURSOR 陳述式所建立之資料指標的名稱。global_cursor_name 也可以是 ODBC 應用程式所開啟,再藉由呼叫 SQLSetCursorName 來命名之 API 伺服器資料指標的名稱。global_cursor_name 是 nvarchar(128)。

  • [ @cursor_identity = ] N'input_cursor_variable'
    這是與開啟的資料指標有關聯的資料指標變數名稱。input_cursor_variable 是 nvarchar(128)。

傳回碼值

傳回的資料指標

sp_describe_cursor_tables 會將它的報表封裝成 Transact-SQLcursor 輸出參數。這會使 Transact-SQL 批次、預存程序和觸發程序能夠使用輸出,每次處理一個資料列。另外,這也表示無法直接從 API 函數呼叫程序。cursor 輸出參數必須繫結到程式變數,但 API 不支援繫結 cursor 參數或變數。

下表顯示 sp_describe_cursor_tables 所傳回的資料指標格式。

資料行名稱

資料類型

描述

table owner

sysname

資料表擁有者的使用者識別碼。

Table_name

sysname

物件或基底資料表的名稱。在 SQL Server 中,伺服器資料指標一律會傳回使用者指定的物件,而不是基底資料表。在 SQL Server 2000 中,除非檢視或函數是利用 WITH VIEW_METADATA 來建立的,否則,伺服器資料指標會傳回基底資料表。

Optimizer_hints

smallint

點陣圖是由下列中的一或多項所組成:

1 = 資料列層級鎖定 (ROWLOCK)

4 = 頁面層級鎖定 (PAGELOCK)

8 = 資料表鎖定 (TABLOCK)

16 = 獨佔資料表鎖定 (TABLOCKX)

32 = 更新鎖定 (UPDLOCK)

64 = 無鎖定 (NOLOCK)

128 = 快速第一資料列選項 (FASTFIRST)

4096 = 當搭配 DECLARE CURSOR (HOLDLOCK) 時,讀取可重複的語意

當提供多個選項時,系統會使用限制性最高的項目。不過,sp_describe_cursor_tables 會顯示查詢所指定的旗標。

lock_type

smallint

針對這個資料指標的每個基底資料表而明確或隱含地要求的捲動鎖定類型。這個值可以是下列值之一:

0 = 無

1 = 共用

3 = 更新

server_name

sysname, nullable

資料表所在連結伺服器的名稱。當使用 OPENQUERY 或 OPENROWSET 時,便是 NULL。

Objectid

int

資料表的物件識別碼。當使用 OPENQUERY 或 OPENROWSET 時,便是 0。

dbid

int

資料表所在資料庫的識別碼。當使用 OPENQUERY 或 OPENROWSET 時,便是 0。

dbname

sysname, nullable

資料表所在資料庫的名稱。當使用 OPENQUERY 或 OPENROWSET 時,便是 NULL。

備註

sp_describe_cursor_tables 會描述伺服器資料指標所參考的基底資料表。如需資料指標所傳回之結果集的屬性描述,請使用 sp_describe_cursor_columns。如需資料指標全域性質的描述,如它的捲動和更新的能力,請使用 sp_describe_cursor。若要取得連接上可見的 Transact-SQL 伺服器資料指標報表,請使用 sp_cursor_list。

權限

需要 public 角色中的成員資格。

範例

下列範例會開啟一個全域資料指標,且會利用 sp_describe_cursor_tables 來報告資料指標所參考的資料表。

USE AdventureWorks2008R2;
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