Truncate Table WITH Partitions SQL Server | Truncate Table SQL Server |
It is a well known fact that TRUNCATE TABLE is faster than DELETE statement. TRUNCATE TABLE SQL Server uses lesser system resources and transaction log file when compared to a DELETE statement.
This is Part 2 of 10 Part T-SQL Enhancements in SQL Server 2016 for Developers and DBAs. Click here to read it from the beginning….
Starting SQL Server 2016, Microsoft has introduced a new clause TRUNCATE TABLE WITH PARTITIONS SQL Server which can be used to truncate all rows available within a partition.
Syntax: TRUNCATE TABLE WITH PARTITIONS
TRUNCATE TABLE [SchemaName].[TableName] WITH (PARTITIONS [Partition Number Expression] | [Range]);
Example Truncate Table with Partitions SQL Server
Execute the below sample code to remove Partitions 12, 14, 16, 17 and 18 in SQL Server 2016 using TRUNCATE TABLE WITH PARTITIONS SQL SERVER clause.
TRUNCATE TABLE Sales.TransactionHistory WITH (PARTITIONS (12, 14, 16 TO 18)) GO
Trending SQL Server Articles and Tips
Clicking Next Page button to continue reading the topics and click on the Previous Page button to revisit the previous topic.
- DROP IF EXISTS
- ALTER TABLE WITH (ONLINE = ON | OFF)
- MAXDOP for DBCC CHECKDB, DBCC CHECKTABLE and DBCC CHECKFILEGROUP
- ALTER DATABASE SET AUTOGROW_SINGLE_FILE
- ALTER DATABASE SET AUTOGROW_ALL_FILES
- COMPRESS and DECOMPRESS Functions
- STRING_SPLIT and STRING_ESCAPE Functions
- FORMATMESSAGE Statement
- SERVERPROPERTY Function
- TRUNCATE TABLE WITH PARTITIONS