QuestionQ83

VerifiedSecure, optimize, and deploy database solutions

You have a SQL database in Microsoft Fabric that contains a table named dbo.Orders.

  • dbo.Orders has a clustered index.
  • It contains three years of data.
  • It is partitioned by a column named OrderDate by month.

You need to remove all rows for the oldest month. The solution must minimize the impact on other queries that access the data in dbo.Orders.

Solution: Execute the following Transact-SQL statement.

TRUNCATE TABLE dbo.Orders;  

Does this accomplish the goal?

Explanation

Without a WITH (PARTITIONS (...)) clause, TRUNCATE TABLE removes every row from the table, not just the oldest monthly partition. Removing all data does not satisfy a requirement to remove only the rows for the oldest month. TRUNCATE TABLE (Transact-SQL) - Microsoft Learn

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!