It is a well known fact that TRUNCATE TABLE is faster than DELETE statement. TRUNCATE TABLE 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 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
Execute the below sample code to remove Partitions 12, 14, 16, 17 and 18 in SQL Server 2016 using TRUNCATE TABLE WITH PARTITIONS clause.
TRUNCATE TABLE Sales.TransactionHistory WITH (PARTITIONS (12, 14, 16 TO 18)) GO
Trending SQL Server Articles and Tips
- How to Restore Analysis Services Database in SQL Server Using SQL Server Management Studio
- SQL Server BULK-LOGGED Recovery Model Step by Step Tutorial with Examples
- How to Configure TempDB on Local Disk in SQL Server 2012/2014 Failover Cluster to Improve Performance
- DIFFERENTIAL Database Backups in SQL Server Step by Step Tutorial with Examples
- Why Model Database Default Settings Customization is Important for SQL Server?
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