SQL Server: What's the limit on number of UNIONs?

前端 未结 3 470
生来不讨喜
生来不讨喜 2021-01-05 01:48

I was wondering if there\'s a limit on a number of UNION\'ed SELECT statements I can send to an SQL Server? I may have up to 36 done in one SQL statement, so it becomes quit

3条回答
  •  臣服心动
    2021-01-05 02:15

    From SQL 2008 BOL

    "Any number of UNION operators can appear in a Transact-SQL statement"

    Also from MSDN "Maximum Capacity Specifications for SQL Server" (2008):

    Batch size (1) 65,536 * Network Packet Size

    Length of a string containing SQL statements (batch size) (1) 65,536 * Network packet size

    (1) Network Packet Size is the size of the tabular data stream (TDS) packets used to communicate between applications and the relational Database Engine. The default packet size is 4 KB, and is controlled by the network packet size configuration option.

    To my mind, that means 268,435,456 bytes when using defaults. Please say your query is shorter than that.

提交回复
热议问题