SQL- UNION ALL a large number of tables

前端 未结 4 1662
萌比男神i
萌比男神i 2021-01-27 07:39

I have a large number of tables (some thousands) containing similar data. I would like to run some reports from these. The table names are similar, so I can get a list of table

4条回答
  •  梦毁少年i
    2021-01-27 08:09

    select 'select * from  '+TABLE_NAME +' union all'
    FROM
     INFORMATION_SCHEMA.TABLES
    WHERE TABLE_NAME LIKE '%chd%'
    ORDER BY TABLE_NAME
    

    remove last union all

提交回复
热议问题