Find all tables whose name ends with a certain suffix

39,825

Try this:

SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.tables 
WHERE TABLE_NAME LIKE '%_History'

OR

SELECT name
FROM sys.tables
WHERE name LIKE '%_History'
Share:
39,825

Related videos on Youtube

4b0
Author by

4b0

Updated on July 09, 2022

Comments

  • 4b0
    4b0 almost 2 years

    I have thousand of tables in database. Some names end with _History.

    For example :

    abc_History
    bcd_History
    123_History
    

    How do I find all tables which name is end with _History.

    Some thing like:

    SELECT
    table_name
    FROM sys.tables WHERE table_name LIKE '_History%'
    

    And

    error : Invalid column name 'table_name'.
    
  • Matthew
    Matthew over 5 years
    I added DISTINCT as there were duplicates in the TABLE_NAME
  • phoenixSid
    phoenixSid almost 3 years
    In oracle, it is FROM ALL_TABLES or ALL_ALL_TABLES. Just thought it might help.