報告服務器游標所引用的基表。
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_variable OUTPUT
聲明游標變量的名稱,該變量接收游標輸出。output_cursor_variable 的數(shù)據(jù)類型為 cursor,沒有默認值。調(diào)用 sp_describe_cursor_tables 時,不能與任何游標相關(guān)聯(lián)。返回的游標是可滾動的動態(tài)只讀游標。
[@cursor_source =] { N'local' | N'global' | N'variable' }
指定是使用本地游標的名稱、全局游標的名稱、還是游標變量的名稱來指定當前正在對其進行報告的游標。參數(shù)是 nvarchar(30)。
, [@cursor_identity = ] N'local_cursor_name' ]
由具有 LOCAL 關(guān)鍵字或默認設(shè)置為 LOCAL 的 DECLARE CURSOR 語句創(chuàng)建的游標的名稱。local_cursor_name 的數(shù)據(jù)類型為 nvarchar(128)。
[@cursor_identity =] N'global_cursor_name'
由具有 GLOBAL 關(guān)鍵字或默認設(shè)置為 GLOBAL 的 DECLARE CURSOR 語句創(chuàng)建的游標的名稱。也可以是由 ODBC 應用程序打開然后通過調(diào)用 SQLSetCursorName 對游標命名的 API 服務器游標的名稱。global_cursor_name 的數(shù)據(jù)類型為 nvarchar(128)。
[@cursor_identity =] N'input_cursor_variable'
與開放游標相關(guān)聯(lián)的游標變量的名稱。input_cursor_variable 的數(shù)據(jù)類型為 nvarchar(128)。
無
sp_describe_cursor_tables 將其報表封裝成 Transact-SQL cursor 輸出參數(shù)。這樣,Transact-SQL 批處理、存儲過程和觸發(fā)器就得以按一次一行的方式處理輸出。它還意味著無法直接從數(shù)據(jù)庫 API 函數(shù)直接調(diào)用該過程。cursor 輸出參數(shù)必須綁定到程序變量,但是數(shù)據(jù)庫 API 不支持綁定 cursor 參數(shù)或變量。
下面是 sp_describe_cursor_tables 返回的游標格式。
列名 | 數(shù)據(jù)類型 | 描述 |
---|---|---|
tableowner | sysname | 表所有者的用戶 ID。 |
Table_name | sysname | 基表的名稱。 |
Optimizer_hints | smallint | 位圖由以下一個或多個選項組成: 1 = 行級鎖定 (ROWLOCK) 如果提供多個選項,系統(tǒng)將使用最有限制性的選項。但是 sp_describe_cursor_tables 按查詢的指定顯示標志。 |
lock_type | smallint | 為該游標的每個基表顯式或隱式地請求的滾動鎖類型。值可以為: 0 = 無 |
server_name | sysname, nullable | 表所在鏈接服務器的名稱。如果使用 OPENQUERY 或 OPENROWSET,則為 NULL。 |
Objectid | int | 表的對象 ID。如果使用 OPENQUERY 或 OPENROWSET,則為 0。 |
dbid | int | 表所在數(shù)據(jù)庫的 ID。如果使用 OPENQUERY 或 OPENROWSET,則為 0。 |
dbname | sysname, nullable | 表所在數(shù)據(jù)庫的名稱。如果使用 OPENQUERY 或 OPENROWSET,則為 NULL。 |
sp_describe_cursor_tables 描述服務器游標所引用的基表。使用 sp_describe_cursor_columns 描述由游標返回的結(jié)果集的特性。使用 sp_describe_cursor 描述游標的全局特性,例如可滾動性和可更新性。使用 sp_cursor_list 可獲得連接時可視的 Transact-SQL 服務器游標的報告。
執(zhí)行權(quán)限默認授予 public 角色。
下面的示例打開一個全局游標,并使用 sp_describe_cursor_tables 報告游標所引用的表。
USE Northwind相關(guān)文章
GO
-- Declare and open a global cursor.
DECLARE abc CURSOR KEYSET FOR
SELECT LastName
FROM Employees
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