Solved

List all SQL View references in a SQLServer 2008R2 server

Posted on 2013-01-04
3
511 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 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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