SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Populate partition

By Federico Iori,

This code is useful when to perform recalculation on very large partitioned tables. It allows to divide the calculation per partition , and works into staging table that are independent from each other

For instance if table has 30 partitions, is possible to run this code IN PARALLEL 30 times,

for example with jobs, or by sqlcmd in batch scripts for windows,

then to switch the results into the target table

It is fast : my test performed a 10mil rows table in about 5 minutes

Limitations: It will work with partitioned tables by range , having PK clustered or nonclustered sorted asc, and no check or foreign key constraints .

Supports data compression , so if the code needs to be compiled on sqlserver2005 is necessary to comment a piece.

Is possible to execute or only to script commands

- Input Parameters:
1. @output_type: S=script only, E=execute only, SE = both
2. @SchemaName - Partitioned Table Schema Name
3. @TabName - Partitioned Table Name
4. @PartitionNo - Partition number to be rebuilded



exec dbo.populate_partition 'S','dbo','POSTPAID_RATED_EVENT',15,
' ( select *
where 1=1
and $partition.Traffic_Data_Monthly_PF(Network_Start_Time) =15 ) qioren'


Warning: Clause with(tablock) could create problems during parallel execution

Total article views: 744 | Views in the last 30 days: 1
Related Articles




URGENT: Error executing scripts......

URGENT: Error executing scripts......


Connditional executing of script

Connditional executing of script


Automated Script to Partition Tables

This script is used to print the alter statement and also partition the table with the respective pa...