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)
Thank this author by sharing:
By Federico Iori, 2010/03/25
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 = both2. @SchemaName - Partitioned Table Schema Name3. @TabName - Partitioned Table Name4. @PartitionNo - Partition number to be rebuilded
Example
exec dbo.populate_partition 'S','dbo','POSTPAID_RATED_EVENT',15,' ( select * from POSTPAID_RATED_EVENT_old a with(tablock)where 1=1 and $partition.Traffic_Data_Monthly_PF(Network_Start_Time) =15 ) qioren'
Warning: Clause with(tablock) could create problems during parallel execution
Partition
URGENT: Error executing scripts......
Connditional executing of script
script execution
This script is used to print the alter statement and also partition the table with the respective pa...