Solved

List all SQL View references in a SQLServer 2008R2 server

Posted on 2013-01-04
3
516 Views
Last Modified: 2013-01-10
Hi Guys,

IS there a way i can figure out where a specific view ("vwSample") sql view is referenced in a SqlServer 2008r2 server.

Thanks
0
Comment
Question by:kishan66
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 200 total points
ID: 38745174
Knock yourself out..

/*
sys.dm_sql_referencing_entities
	Returns one row for each entity in the current database that references another user-defined entity by name
	http://msdn.microsoft.com/en-us/library/bb630351.aspx

sys.dm_sql_referenced_entities
	Returns one row for each user-defined entity referenced by name in the definition of the specified referencing entity. 
	http://msdn.microsoft.com/en-us/library/bb677185.aspx
	
	QUESTION:  What objects ARE [referenced by | referencing] X?
*/

-- The following example returns the entities (tables and columns) that are referenced by the database-level DDL trigger ddlDatabaseTriggerLog.

USE AdventureWorks2008R2;
GO

/*
Quesiton:  What objects are referenced by X?
           What tables, views, functions, etc.  does my really long SP reference? 
	SELECT blah, blah, balh
	FROM sys.dm_sql_referenced_entities ('My Object Name', 'OBJECT');
*/

SELECT referenced_schema_name, referenced_entity_name, referenced_minor_name, referenced_minor_id, referenced_class_desc
FROM sys.dm_sql_referenced_entities ('ddlDatabaseTriggerLog', 'DATABASE_DDL_TRIGGER');
GO

-- The following example returns the entities that are referenced by the user-defined function dbo.ufnGetContactInformation.
SELECT referenced_schema_name, referenced_entity_name, referenced_minor_name, referenced_minor_id, referenced_class_desc, is_caller_dependent, is_ambiguous
FROM sys.dm_sql_referenced_entities ('dbo.ufnGetContactInformation', 'OBJECT');
GO

/*
Question:  What objects are referencing X?
           What functions, stored procs, check constraints, etc. call my table? 
*/

SELECT referencing_schema_name, referencing_entity_name, referencing_id, referencing_class_desc, is_caller_dependent
FROM sys.dm_sql_referencing_entities ('Production.Product', 'OBJECT');
GO

Open in new window

0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 200 total points
ID: 38748802
For a different approach download Red-Gate's add-in SQL Search to find all the instances of the VIEW in the same database or all databases.
0
 
LVL 12

Assisted Solution

by:sachitjain
sachitjain earned 100 total points
ID: 38751201
Right click the view and click View dependencies in SQL Server Management Studio's object explorer. This would provide you 2 options:
Objects that depend on [ViewName]
Objects on which [Viewname] depends
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question