One solution for SQL Server to reference a maximum of 256 tables

Source: Internet
Author: User

A problem occurred recently during bug fixing. The system dynamically creates a view based on the number of projects to combine some data of all projects. When the number of projects in the system exceeds 256, the problem occurs. SQL Server throws the following exception:

MSG 106, Level 15, state 1, procedure vsp_t, line 256

Too partition table names in the query. the maximum allowable is 256.

 

Of course, it is a poor design to Union the data of all projects into one view. However, it is really difficult to change this design,What should we do?

 

Tests showed that SQL Server T-SQL batch processing fully supports more than 256 union256 tables, and stored procedures also support referencing more than tables.

 

Therefore, the statement used to create a view is changed from create view to create procedure without any parameters. The SQL statement originally called in select * from view is changed to Exec.

 

In this way, the number of system projects is no longer limited to 256.

 

However, when there are as many as 10000 projects in the system, it takes more than a dozen seconds to create a data stored procedure for all the Union projects, and it takes more than four minutes to execute the stored procedure. Therefore, to fundamentally solve this problem, we should avoid the case of multi-Table union or join in design!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.