Problem: How to delete partitioned table data from a table without dropping the table?
Solution:
TRUNCATE
TABLE, SQL server 2016 and later
In
some cases, where you want to clear out the existing data from the table to
load the table fresh. You may want to delete it fast without logging the rows
that have been deleted.
TRUNCATE TABLE is faster and uses fewer system and
transaction log resources.
Syntax:
TRUNCATE TABLE
[ {
database_name .[ schema_name ] . | schema_name . } ]
table_name
[ WITH (
PARTITIONS ( { <partition_number_expression> | <range> }
[ , ...n ] ) )
]
[ ; ]
Limitations:
1.
A table that has foreign keys
2. A table that participates in an indexed view
3. Replicated tables
2. A table that participates in an indexed view
3. Replicated tables
Example:
In this example, I would like to show we can truncate
specific partitions inside a partitioned table.
To know more about how to create a partitioned table please
go through the following article. Partitioning
a table
TRUNCATE TABLE dbo.Employees WITH (PARTITIONS (2,3, 4));
GO
Results:
0 comments:
Post a Comment