事件
3月31日 下午11時 - 4月2日 下午11時
規模最大的 SQL、Fabric 與 Power BI 學習盛會。 3 月 31 日至 4 月 2 日。 使用代碼 FABINSIDER 可節省 $400。
立即報名
適用於:SQL Server
Azure SQL 資料庫
Azure SQL 受控執行個體
您可使用 SQL Server Management Studio 或 Transact-SQL,在 SQL Server 中取得的使用者定義函式的定義或屬性相關資訊。 您可能需要查看函數的定義才能了解如何從來源資料表衍生出資料;或是查看函數所定義的資料。
如果變更函數所參考的物件名稱,就必須修改該函數,使其文字反映新的名稱。 因此,在改變物件名稱時,首先要檢視此物件的相依性以了解是否有相關的函數受到影響。
若要使用 sys.sql_expression_dependencies
尋找函數的所有相依性,需要資料庫的 VIEW DEFINITION 權限以及資料庫之 sys.sql_expression_dependencies
的 SELECT 權限。 系統物件定義是公開可見的,就像 OBJECT_DEFINITION 中傳回的定義一樣。
在物件總管中,選取資料庫旁的加號,此資料庫包含您想查看屬性的函式,然後選取加號以展開 [可程式性] 資料夾。
選擇加號以展開函式資料夾。
選取加號,展開包含您要檢視其屬性之函式的資料夾:
以滑鼠右鍵按一下要查看其屬性的函數,然後選取 [屬性]。
下列屬性會出現在 [函式屬性 - function_name] 對話方塊中。
函式名稱 | 描述 |
---|---|
資料庫 | 包含此函數之資料庫的名稱。 |
伺服器 | 目前伺服器執行個體的名稱。 |
使用者 | 這個連接之使用者的名稱。 |
建立日期 | 顯示建立函數的日期。 |
以...身份執行 | 函數的執行內容。 |
名稱 | 目前函數的名稱。 |
架構 | 顯示擁有函數的結構描述。 |
系統物件 | 指出函數是否為系統物件。 值為 True 和 False 。 |
ANSI NULLS | 指出物件是否使用 ANSI NULLS 選項建立。 |
已加密 | 指出函數是否加密。 值為 True 和 False 。 |
函數類型 | 使用者定義函數的類型。 |
帶引號的識別符 | 指出物件是否使用引號識別碼選項建立。 |
結構描述繫結 | 指出函數是否綁定到結構。 值為 True 與 False。 如需結構描述繫結函式的資訊,請參閱 CREATE FUNCTION (Transact-SQL) 的 SCHEMABINDING 部分。 |
在物件總管中,連線到資料庫引擎的執行個體。
在標準列上,選取 [新增查詢] 。
將下列其中一個範例複製並貼到查詢視窗中,然後按一下 [執行]。
下列程式碼範例會取得函式名稱、定義和相關屬性。
USE AdventureWorks2022;
GO
-- Get the function name, definition, and relevant properties
SELECT sm.object_id,
OBJECT_NAME(sm.object_id) AS object_name,
o.type,
o.type_desc,
sm.definition,
sm.uses_ansi_nulls,
sm.uses_quoted_identifier,
sm.is_schema_bound,
sm.execute_as_principal_id
-- using the two system tables sys.sql_modules and sys.objects
FROM sys.sql_modules AS sm
JOIN sys.objects AS o ON sm.object_id = o.object_id
-- from the function 'dbo.ufnGetProductDealerPrice'
WHERE sm.object_id = OBJECT_ID('dbo.ufnGetProductDealerPrice')
ORDER BY o.type;
GO
下列程式碼範例會取得範例函式 dbo.ufnGetProductDealerPrice
的定義。
USE AdventureWorks2022;
GO
-- Get the definition of the function dbo.ufnGetProductDealerPrice
SELECT OBJECT_DEFINITION (OBJECT_ID('dbo.ufnGetProductDealerPrice')) AS ObjectDefinition;
GO
如需詳細資訊,請參閱 sys.sql_modules (Transact-SQL) 和 OBJECT_DEFINITION (Transact-SQL)。
在物件總管中,連線到資料庫引擎的執行個體。
在標準列上,選取 [新增查詢] 。
複製下列範例並將其貼到查詢視窗中,然後選取 [執行]。
USE AdventureWorks2022;
GO
-- Get all of the dependency information
SELECT OBJECT_NAME(sed.referencing_id) AS referencing_entity_name,
o.type_desc AS referencing_description,
COALESCE(COL_NAME(sed.referencing_id, sed.referencing_minor_id), '(n/a)') AS referencing_minor_id,
sed.referencing_class_desc, sed.referenced_class_desc,
sed.referenced_server_name, sed.referenced_database_name, sed.referenced_schema_name,
sed.referenced_entity_name,
COALESCE(COL_NAME(sed.referenced_id, sed.referenced_minor_id), '(n/a)') AS referenced_column_name,
sed.is_caller_dependent, sed.is_ambiguous
-- from the two system tables sys.sql_expression_dependencies and sys.object
FROM sys.sql_expression_dependencies AS sed
INNER JOIN sys.objects AS o ON sed.referencing_id = o.object_id
-- on the function dbo.ufnGetProductDealerPrice
WHERE sed.referencing_id = OBJECT_ID('dbo.ufnGetProductDealerPrice');
GO
如需詳細資訊,請參閱 sys.sql_expression_dependencies (Transact-SQL) 與 sys.objects (Transact-SQL)。
事件
3月31日 下午11時 - 4月2日 下午11時
規模最大的 SQL、Fabric 與 Power BI 學習盛會。 3 月 31 日至 4 月 2 日。 使用代碼 FABINSIDER 可節省 $400。
立即報名