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 Fix Cannot execute script. Insufficient memory to continue the execution of the program (mscorlib) error in SQL Server
- ALTER DATABASE SET AUTOGROW_ALL_FILES T-SQL Enhancement in SQL Server 2016
- COPY_ONLY Backup in SQL Server Step by Step Tutorial with Examples
- How to Enable and Refresh IntelliSense in SQL Server Management Studio (SSMS)
- SQL Server FULL Recovery Model Step by Step Tutorial with Examples
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