Sql 有没有一种方法可以显示联合中行的表组织

Sql 有没有一种方法可以显示联合中行的表组织,sql,sql-server,union,Sql,Sql Server,Union,当I union n个表的数量时,是否有方法向结果集中添加一列,说明该行来自哪个表?当然-向每个语句添加硬编码的文本列 select 'This came from table A' as SourceTable, Id, Name from TableA -- union -- select 'This came from table B' as SourceTable, Id, Name from TableB 没问题-如果你能把这个标记为答案,我将不胜感激。我不得不等待时间限制

当I union n个表的数量时,是否有方法向结果集中添加一列,说明该行来自哪个表?

当然-向每个语句添加硬编码的文本列

select 'This came from table A' as SourceTable, Id, Name
  from TableA
--
union
--
select 'This came from table B' as SourceTable, Id, Name
  from TableB

没问题-如果你能把这个标记为答案,我将不胜感激。我不得不等待时间限制