Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
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: 727 | Views in the last 30 days: 2
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...

data warehousing    
very large table    

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones