Mos*_*026 0 sql t-sql stored-procedures
我希望在一个存储过程中获得此查询的结果.与此查询我要返回的行数table1来table4
select count(*) from table1
select count(*) from table2
select count(*) from table3
select count(*) from table4
Run Code Online (Sandbox Code Playgroud)
我希望将此结果放在临时表中并选择临时表的所有列.
这是一个不太优雅的解决方案:
SELECT 'table1' as table_name, COUNT(*) as record_count from table1
UNION ALL
SELECT 'table2' as table_name, COUNT(*) as record_count from table2
UNION ALL
SELECT 'table3' as table_name, COUNT(*) as record_count from table3
UNION ALL
SELECT 'table4' as table_name, COUNT(*) as record_count from table4
Run Code Online (Sandbox Code Playgroud)