MSSQLSERVER_2020

적용 대상:SQL Server

세부 사항

attribute
제품 이름 SQL Server
이벤트 ID 2020
이벤트 원본 MSSQLSERVER
구성 요소 SQLEngine
심볼 이름
메시지 텍스트 엔터티 "%.*ls"에 대해 보고된 종속성에는 열에 대한 참조가 포함되지 않습니다. 엔터티가 존재하지 않는 개체를 참조하거나 엔터티의 하나 이상의 문에 오류가 있기 때문입니다. 쿼리를 다시 실행하기 전에 엔터티에 오류가 없고 엔터티에서 참조하는 모든 개체가 있는지 확인합니다.

설명

sys.dm_sql_referenced_entities 시스템 함수는 스키마 바운드 참조에 대한 열 수준 종속성을 보고합니다. 예를 들어 인덱싱된 뷰에는 스키마 바인딩이 필요하기 때문에 함수는 인덱싱된 뷰에 대한 모든 열 수준 종속성을 보고합니다. 그러나 참조된 엔터티가 스키마 바인딩되지 않은 경우 열이 참조되는 모든 문을 바인딩할 수 있는 경우에만 열 종속성이 보고됩니다. 문이 구문 분석될 때 모든 개체가 존재하는 경우에만 문을 성공적으로 바인딩할 수 있습니다. 엔터티에 정의된 문을 바인딩할 수 없으면 열 종속성이 보고되지 않고 referenced_minor_id 열이 0을 반환합니다. 열 종속성을 확인할 수 없으면 오류 2020이 발생합니다. 이 오류는 쿼리가 개체 수준 종속성을 반환하는 것을 방지하지 않습니다.

사용자 작업

오류 2020보다 먼저 나타나는 메시지에서 확인된 모든 오류를 수정합니다. 예를 들어 다음 코드 예제에서는 뷰 Production.ApprovedDocuments 가 열 및 Production.DocumentStatus 테이블에 정의됩니다TitleChangeNumber. sys.dm_sql_referenced_entities 시스템 함수는 ApprovedDocuments 뷰가 종속된 개체와 열에 대해 쿼리됩니다. WITH SCHEMA_BINDING 절을 사용하여 뷰를 만들지 않으므로 뷰에서 참조되는 열을 참조된 테이블에서 수정할 수 있습니다. 이 예에서는 ChangeNumber 테이블에 있는 Production.Document 열의 이름을 TrackingNumber로 변경합니다. 카탈로그 뷰는 뷰에 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)