If you need a single resultset and all tables have the same layout, this should work:
DECLARE @sql nvarchar(4000) =
(SELECT STRING_AGG(CONCAT(
'SELECT ''',
QUOTENAME(name),
''',
* FROM ',
QUOTENAME(name),
'..Table ',
CHAR(10)
), ' UNION ALL ' + CHAR(10))
FROM sys.databases);
SELECT @sql; -- for checking
EXEC(@sql);
If you're on compatibility level 130 or lower, you will have to use XML PATH(TYPE, '')
to aggregate. I will leave that to you.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…