Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find all tables whose name ends with a certain suffix

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'.
like image 302
4b0 Avatar asked Jan 09 '14 06:01

4b0


1 Answers

Try this:

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

OR

SELECT name
FROM sys.tables
WHERE name LIKE '%_History'
like image 131
Saharsh Shah Avatar answered Oct 05 '22 06:10

Saharsh Shah