SQL Server 2016 – Truncate Table Supports Partitioning

SQL Server 2016 – Truncate Table Supports Partitioning

It’s been a month after the new year started. Hope everyone is having a wonderful time.

This is my first post for this year and it’s a simple one but most of them are looking around for this option quite from SQL Server 2012.

Applies to

  • SQL Server 2016 and Above

In earlier when we work with table paritioning and when we want to truncate a pariticular partition we have to rely on partition switching only. How ever from SQL Server 2016 we have the facility to truncate data at partition level. It’s pretty straight forward, sample command below.

USE mydb
GO
--Individual Partitions
TRUNCATE TABLE MyTable WITH (PARTITIONS (7, 11))
GO
--Range of Parititions
TRUNCATE TABLE MyTable WITH (PARTITIONS (30 TO 40));
GO 

Leave a Reply

Leave a Reply

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

*


x

Related Posts

Batch script to deploy multiple SQL files
I was working on a project where I’m supposed to deploy lots of SQL Server script files (.sql). It’s very tedious job either to manually execute ...
Difference between TRUNCATE and DELETE command
  Lets see the difference between DELETE and TRUNCATE command as below DELETE TRUNCATE DML Statement DDL Statemen...
Batch Script to Deploy Multiple SQL files (Version 2)
I took very long break to keep the site up to date with my learning. Few years back I wrote an article to deploy multiple scripts using batch fil...
powered by RelatedPosts