
To Combine Partitioned Data Across Servers
The Transact-SQL UNION set operator can be used within a view to combine the results of two or more queries from separate tables into a single result set. This appears to the user as a single table that is called a partitioned view. For example, if one table contains sales data for Washington, and another table contains sales data for California, a view could be created from the UNION of those tables. The view represents the sales data for both regions.
To use partitioned views, you create several identical tables, specifying a constraint to determine the range of data that can be added to each table. The view is then created that uses these base tables. When the view is queried, SQL Server automatically determines which tables are affected by the query and references only those tables. For example, if a query specifies that only sales data for the state of Washington is required, SQL Server reads only the table that contains the Washington sales data; no other tables are accessed.
Partitioned views can be based on data from multiple heterogeneous sources, such as remote servers, to create a federation of database servers. For example, to combine data from different remote servers each of which stores data for a different region of your organization, you can create distributed queries that retrieve data from each data source, and then create a view based on those distributed queries. Any queries read only data from the tables on the remote servers that contains the data requested by the query; the other servers referenced by the distributed queries in the view are not accessed.
When you partition data across multiple servers, queries accessing only a fraction of the data can run faster because there is less data to scan. If the tables are located on different servers, or on a computer that uses multiple processors, each table involved in the query can also be scanned in parallel. This can improve query performance. Additionally, maintenance tasks, such as rebuilding indexes or backing up a table, can execute more quickly.
By using a partitioned view, the data still appears as a single table and can be queried as such without having to manually reference the correct underlying table.
Note: |
|---|
|
The preferred method for partitioning data local to one server is through partitioned tables. For more information, see Partitioned Tables and Indexes.
|
Partitioned views are updatable if either of the following conditions is met:
-
An INSTEAD OF trigger is defined on the view with logic to support INSERT, UPDATE, and DELETE statements.
-
Both the view and the INSERT, UPDATE, and DELETE statements follow the rules defined for updatable partitioned views. For more information, see Creating Partitioned Views.