DBA

Table Partition Truncate partition part 4

Advertisements

Truncate

Truncate partition will truncate the partition and leave as empty then we can merge it.

MSDN: Specifies the partitions to truncate or from which all rows are removed. If the table isn’t partitioned, the WITH PARTITIONS argument generates an error. If the WITH PARTITIONS clause isn’t provided, the entire table is truncated.

Test Code:

Use the same script used in part 1 for creating database and table.

-- delete b/w 1 to 6
TRUNCATE TABLE [tbl_partition_test] WITH (PARTITIONS (2 TO 5));
GO
-- delete only 3,5 & 6
TRUNCATE TABLE [tbl_partition_test] WITH (PARTITIONS (3,5,6))
-- delete only 4	
TRUNCATE TABLE [tbl_partition_test] WITH (PARTITIONS (4));


-- The truncate partition no or range partition no will remove all data from the partition make sure you take backup by switch out
-- if you really do not want the data you can truncate the partition

 

I’m currently working as a SQL server DBA in one of the top MNC. I’m passionate about SQL Server And I’m specialized in Administration and Performance tuning. I’m an active member of SQL server Central and MSDN forum. I also write articles in SQL server Central. For more Click here

Leave a Reply

Your email address will not be published. Required fields are marked *

1 + 2 =