Querying for mulitiple tables

  • Hi,

    I am trying to run the following query against an auditee's database.  However, I only want to run it to show two or three tables.  How would I edit the second to last row (Where T.name = 'table_name'') to for multiple table names?  I tried putting 'or' between the table names, but that did not work.

    SELECT OBJECT_SCHEMA_NAME(T.[object_id],DB_ID()) AS [Schema],
            T.name AS table_name, AC.name AS column_name, 
       TY.name AS system_data_type, AC.max_length 
    FROM sys.tables AS T 
    INNER JOIN sys.all_columns AC ON T.object_id = AC.object_id
    INNER JOIN sys.types TY ON AC.system_type_id = TY.system_type_id AND AC.user_type_id = TY.user_type_id
    --WHERE T.is_ms_shipped = 0
    Where T.name = 'table_name'
    ORDER BY T.name, AC.column_id

  • Hi,

    You have two choices;


    SELECT OBJECT_SCHEMA_NAME(T.[object_id],DB_ID()) AS [Schema],
    T.name AS table_name, AC.name AS column_name,
    TY.name AS system_data_type, AC.max_length
    FROM sys.tables AS T
    INNER JOIN sys.all_columns AC ON T.object_id = AC.object_id
    INNER JOIN sys.types TY ON AC.system_type_id = TY.system_type_id AND AC.user_type_id = TY.user_type_id
    --WHERE T.is_ms_shipped = 0
    Where T.name = 'table_name' OR T.name = 'table_name1' OR T.name = 'table_name2'
    ORDER BY T.name, AC.column_id


    SELECT OBJECT_SCHEMA_NAME(T.[object_id],DB_ID()) AS [Schema],
    T.name AS table_name, AC.name AS column_name,
    TY.name AS system_data_type, AC.max_length
    FROM sys.tables AS T
    INNER JOIN sys.all_columns AC ON T.object_id = AC.object_id
    INNER JOIN sys.types TY ON AC.system_type_id = TY.system_type_id AND AC.user_type_id = TY.user_type_id
    --WHERE T.is_ms_shipped = 0
    Where T.name IN ('table_name', 'table_name1', 'table_name2')
    ORDER BY T.name, AC.column_id

    Cheers,

    Rodders...

  • Option 3:
    WHERE T.name LIKE '%table_pattern%'

Viewing 3 posts - 1 through 2 (of 2 total)

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