locked
Need a SQL query to list the table names used in a view. RRS feed

  • Question

  • User1835742922 posted

    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

    Saturday, September 8, 2012 1:28 AM

Answers

  • User77042963 posted

    Try this query:

    SELECT Table_Name
    FROM   [INFORMATION_SCHEMA].[VIEW_TABLE_USAGE]
    WHERE  View_Name = 'yourViewName' 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 10, 2012 5:23 PM

All replies

  • User3866881 posted

    Need a SQL query to list the table names used in a view.

    Hi,

    Please just create a View and do this:

    Create View MyView
    As
      Select [name] from sysobjects where type='U'
    Monday, September 10, 2012 3:50 AM
  • User1835742922 posted

    Hi Decker,

    Thanx for your reply,

    It is showing only user-defined tables.

    But i want to display tables name against view name. Like i have created view MyViews from two tables (Table_1, Table_2).

    Now i want a query that dispaly view information in following manner.

    View Name      Table Name
    MyViews          Table_1,Table_2 etc

    Thanx

    Monday, September 10, 2012 7:40 AM
  • User77042963 posted

    Try this query:

    SELECT Table_Name
    FROM   [INFORMATION_SCHEMA].[VIEW_TABLE_USAGE]
    WHERE  View_Name = 'yourViewName' 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 10, 2012 5:23 PM