Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

List all SQL View references in a SQLServer 2008R2 server

Posted on 2013-01-04
3
Medium Priority
?
522 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
3 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 800 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 800 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 400 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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Loops Section Overview

916 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