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 Start SQL Server without TempDB Database
- How to Restore Analysis Services Database in SQL Server Using SQL Server Management Studio
- How to Repair Database in Suspect Mode in SQL Server
- How to Get SQL Server Instance Information
- How to Change SQL Server Login Properties to Enforce Password Policies and Expiration Settings
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