Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

View - Table Usage (Recursive)

By Rhett Clement,

Wrote this to analyze the tables that are contained in a view. The problem I had with the INFORMATION_SCHEMA.VIEW_COLUMN_USAGE view is that if one view queries another it reports the view as the Base Table, not the actual database table the data comes from. Considering that this is a legal column definition in a view "1 As Id" then we can see why INFORMATION_SCHEMA doesn't attempt to dig down and tell us where that data came from, since the correct answer could be NULL.

But there are so many times when are views are 'honest' queries between multiple related tables and the occasional view. So if that's what you have this may be a useful way for you to uncover the tables that made up your view, without individually looking at the dependencies visualizer for each view or spending $$$ on software to do that for us. This query attempts to assist in that situation. I say attempts because it is not heavily tested and has limitations as I've hinted at above.

Also includes two other queries that show different summaries of the same data. Intended as an analysis query not something to use in a prodcution app. Requires SQL 2005 or higher. Written on SQL 2005.

I imagine community members will be able to point out additional issues or enhancements. I welcome your feedback.

 

Total article views: 1001 | Views in the last 30 days: 3
 
Related Articles
FORUM

Xquery issue attempting to update an attribute

receiving an error when attempting to add a leading character to a already existing string

ARTICLE

DAX Query Basics

In this document I will attempt to talk you through writing your first very simple DAX queries. For ...

FORUM

How to Refer to A Computed Column in Access-SQL Database Query

Errors created when attempt to use a Computer Column in Query

BLOG

How to parameterize a TOP values query

There are certain key words in a T-SQL query than cannot be parameterized, including the TOP statem...

BLOG

Bad Default Database Leads to a Failed Login Attempt

Yesterday we had a user receiving the infamous failed login attempt error (no, that's not a valid IP...

Tags
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones