September 7, 2012 at 11:40 pm
Dear All,
I have a view with 7 to 9 tables and it is running slow so i need a query to list all the table names used in a view.
the query should populate as:-
view Table
____ _____
view1 tab1
view1 tab1
Can anyone help me?
Thanx
Neel
September 8, 2012 at 12:11 am
Surely the Execution Plan would be a better place to start, if performance optimisation is your goal?
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
September 8, 2012 at 5:30 am
Thanx Phil
But i need a query to find out tables which are used by view.
September 8, 2012 at 5:48 am
can you post the view definition?
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
September 8, 2012 at 8:17 am
If it's just one view, you could script it out.
Otherwise, this seems to work in SQL Server 2012:
use AdventureWorks2012;
select VIEW_DEFINITION from INFORMATION_SCHEMA.VIEWS
where TABLE_NAME='vSalesPerson';
September 8, 2012 at 9:37 am
including the columns referenced:
select
OBJECT_NAME(depz.object_id),
OBJECT_NAME(depz.referenced_major_id),
colz.name,
*
from sys.sql_dependencies depz
left outer join sys.columns colz
on depz.object_id = colz.object_id
and depz.referenced_minor_id=colz.column_id
where OBJECT_NAME(depz.object_id) = 'YourViewName'
Lowell
September 11, 2012 at 10:58 pm
Thank you very much Lowell.
This is the right query i was looking for.
Thanx Again.
September 12, 2012 at 1:05 am
Hi Lowell,
Your query showing tables of any view, but if view contains another view then it is not showing name of that view.
Can u help me in this regard.
Thanx
Neel
September 12, 2012 at 5:34 am
neellotus07 (9/12/2012)
Hi Lowell,Your query showing tables of any view, but if view contains another view then it is not showing name of that view.
Can u help me in this regard.
Thanx
Neel
Are you sure? when i just tested a view which i KNOW contains a mix of other views and tables, i get the list of exactly what is referenced int he view; i would need to "drill down", so to speak , to get the tables that teh internal views hit; is that what you are asking? the way you framed the question makes me think the results don't show the views at all.
can you clarify the issue?
Lowell
September 12, 2012 at 6:53 pm
Another way:
-- To get just the table names
SELECT DISTINCT TABLE_NAME
FROM information_schema.view_column_usage
WHERE VIEW_NAME = 'v_YourView'
-- To get table and column names
SELECT TABLE_NAME, COLUMN_NAME
FROM information_schema.view_column_usage
WHERE VIEW_NAME = 'v_YourView'
My thought question: Have you ever been told that your query runs too fast?
My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
Since random numbers are too important to be left to chance, let's generate some![/url]
Learn to understand recursive CTEs by example.[/url]
[url url=http://www.sqlservercentral.com/articles/St
September 12, 2012 at 8:36 pm
neellotus07 (9/7/2012)
Dear All,I have a view with 7 to 9 tables and it is running slow so i need a query to list all the table names used in a view.
the query should populate as:-
view Table
____ _____
view1 tab1
view1 tab1
Can anyone help me?
Thanx
Neel
Gosh... What a strange question. I know you have the answer but if you have a view that is running slow, just listing the names of the tables in the view code isn't going to do much to help.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply