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,
This script requires the creation of the big view in
Works with heap, clustered index, compressed tables
It is similar functionality as
But it is a bit more powerful and flexible
1) Create an empty DEST_TABLE identical to SOURCE_TABLE
exec dbo.sp_truncate_partitions 'COPYTABLE', 'SOURCE_TABLE' , 'DEST_TABLE', null,null
This table can be used, for example, as stage table during an ETL process.
2) Like 1 , then switch the partitions from '2013-01-01' up to '2013-02-02' to DEST_TABLE
exec dbo.sp_truncate_partitions 'SWITCH', 'DIM_CONTRACT_SIM_SERIAL' , 'tmp_DIM_CONTRACT_SIM_SERIAL_ZZZ', '2013-01-01', '2013-02-02'
3) The same as 2 , then drops DEST_TABLE
exec dbo.sp_truncate_partitions 'DELETE', 'DIM_CONTRACT_SIM_SERIAL' , 'tmp_DIM_CONTRACT_SIM_SERIAL_ZZZ', '2013-01-01', '2013-02-02'
Procedure to automatically truncate table partition
Wouldn't be great if you could truncate any partition of a partitioned table with one T-SQL statemen...
If you are using partitions in SQL Server, be aware that “partition switching” is a great feature to...