【问题标题】:How to union many tables with same name but different schema without dynamic sql?如何在没有动态 sql 的情况下联合许多具有相同名称但不同模式的表?
【发布时间】:2017-02-14 06:04:25
【问题描述】:

Microsoft SQL Server

  • [dbo].[MyTable]
  • [schema1].[MyTable]
  • [schema2].[MyTable]
  • [schema3].[MyTable]

我想联合他们。例如:

select * from [*].[MyTable]

我可以这样做吗?

【问题讨论】:

    标签: sql sql-server dynamic schema union


    【解决方案1】:

    像这样的

    select * from [dbo].[MyTable]
    UNION
    select * from [schema1].[MyTable]
    UNION
    select * from [schema2].[MyTable]
    UNION
    select * from [schema3].[MyTable]
    

    【讨论】:

    • 很遗憾,如果不使用动态 SQL,我无法列出表的名称。
    猜你喜欢
    • 1970-01-01
    • 2018-05-09
    • 2015-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-01
    • 1970-01-01
    • 2022-11-19
    相关资源
    最近更新 更多