MSSQLSERVER_2020

適用於:SQL Server

詳細資料

屬性
產品名稱 SQL Server
事件識別碼 2020
事件來源 MSSQLSERVER
元件 SQLEngine
符號名稱
訊息文字 針對實體 "%.*ls" 所報告的相依性不包含資料行的參考。 這是因為此實體參考了不存在的物件,或是此實體中的一個或多個陳述式發生錯誤。 在重新執行查詢以前,請確定此實體中沒有任何錯誤,而且此實體參考的所有物件都存在。

說明

sys.dm_sql_referenced_entities 系統函式會報告架構系結參考的任何資料行層級相依性。 例如,函式會報告索引檢視表的所有資料行層級相依性,因為索引檢視需要架構系結。 不過,當參考的實體不是架構系結時,只有在參考資料行的所有語句都可以系結時,才會報告資料行相依性。 只有在剖析語句時,所有物件都存在時,才能成功系結語句。 如果實體中定義的任何語句無法系結,則不會報告 資料行相依性,且referenced_minor_id 資料行會傳回 0。 無法解析資料行相依性時,會引發錯誤 2020。 此錯誤不會防止查詢傳回物件層級相依性。

使用者動作

更正錯誤 2020 之前訊息中識別的任何錯誤。 例如,在下列程式碼範例中,檢視 Production.ApprovedDocuments 是在 資料表中的資料行 TitleChangeNumberStatusProduction.Document 上定義。 系統會 針對檢視相依的物件和資料 ApprovedDocuments 行查詢sys.dm_sql_referenced_entities 系統函式。 由於檢視不是使用 WITH SCHEMA_BINDING 子句建立,因此可以在參考資料表中修改檢視中參考的資料行。 此範例會將資料表中的資料行重新命名為 TrackingNumber 來改變 ChangeNumber 資料表中的資料 Production.Document 行。 檢視會再次 ApprovedDocuments 查詢目錄檢視;不過,它無法系結至檢視中定義的所有資料行。 錯誤 207 和 2020 會傳回識別問題。 若要解決此問題,必須改變檢視以反映資料行的新名稱。

USE AdventureWorks2022;  
GO  
CREATE VIEW Production.ApprovedDocuments  
AS  
SELECT Title, ChangeNumber, Status  
FROM Production.Document  
WHERE Status = 2;  
GO  
SELECT referenced_schema_name AS schema_name  
,referenced_entity_name AS table_name  
,referenced_minor_name AS referenced_column  
FROM sys.dm_sql_referenced_entities ('Production.ApprovedDocuments', 'OBJECT');  
GO  
EXEC sp_rename 'Production.Document.ChangeNumber', 'TrackingNumber', 'COLUMN';  
GO  
SELECT referenced_schema_name AS schema_name  
,referenced_entity_name AS table_name  
,referenced_minor_name AS referenced_column  
FROM sys.dm_sql_referenced_entities ('Production.ApprovedDocuments', 'OBJECT');  
GO

查詢會傳回下列錯誤訊息。

Msg 207, Level 16, State 1, Procedure ApprovedDocuments, Line 3  
Invalid column name 'ChangeNumber'.  
Msg 2020, Level 16, State 1, Line 1  
The dependencies reported for entity  
"Production.ApprovedDocuments" do not include references to  
columns. This is either because the entity references an  
object that does not exist or because of an error in one or  
more statements in the entity. Before rerunning the query,  
ensure that there are no errors in the entity and that all  
objects referenced by the entity exist.

下列範例會更正檢視中的資料行名稱。

USE AdventureWorks2022;  
GO  
ALTER VIEW Production.ApprovedDocuments  
AS  
SELECT Title,TrackingNumber, Status  
FROM Production.Document  
WHERE Status = 2;  
GO

另請參閱

sys.dm_sql_referenced_entities (Transact-SQL)