Add to query to show if populated

  • I have this query - problem is my results bring back hundreds of tables..

    I need to know if the tables it returns have records in them (most do not) So, I can update just the tables that have data.

    SELECT t.name AS table_name,

    SCHEMA_NAME(schema_id) AS schema_name,

    c.name AS column_name

    FROM sys.tables AS t

    INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID

    WHERE c.name LIKE '%tin%'

    ORDER BY schema_name, table_name;

    How can I add that to the above statement?

  • join to sysindexes on indexID IN ( 0, 1) and check the row column.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • .. can anyone help me with the syntax?

  • Sorry, got distracted:

    SELECT t.name AS table_name,

    SCHEMA_NAME(schema_id) AS schema_name,

    c.name AS column_name

    FROM sys.tables AS t

    INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID

    JOIN sysindexes AS i ON i.id = t.object_id

    WHERE c.name LIKE '%n%'

    AND i.indid IN ( 0, 1)

    AND i.rowcnt > 0

    ORDER BY schema_name, table_name;


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • lol...awesome thanks craig!

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply