簡體   English   中英

有沒有辦法從分區表中刪除范圍值(sql server 2012)

[英]Is there a way to drop a range value from a partition table (sql server 2012)

我有一個分區表“TableA”。 我在列名“RecorDate”(日期類型)上創建了一個分區。 有過去 6 個月的記錄,我不想保存它們,我想刪除它們。

是否有一種簡單的方法可以刪除范圍值或特定分區號(甚至是所有范圍,例如“01-01-2014”到“01-01-2015”)。

類似於在 ORACLE 中, TRUNCATE TABLE WITH(PARTITION(x,y to z))

順便說一句,我知道 switch partition 命令,將范圍移動到另一個表,然后執行該命令

TRUNCATE TABLE TableNameb ;
GO

10倍

TRUNCATE WITH PARTITION將在 SQL Server 2016 中可用

WITH ( 分區 ( { | } [ , ...n ] ) )

 Applies to: SQL Server (SQL Server 2016 Community Technology Preview 2 (CTP2) through current version). Specifies the partitions to truncate or from which all rows are removed. If the table is not partitioned, the WITH PARTITIONS argument

會產生錯誤。 如果未提供 WITH PARTITIONS 子句,則整個表將被截斷。

 <partition_number_expression> can be specified in the following ways: Provide the number of a partition, for example: WITH (PARTITIONS (2)) Provide the partition numbers for several individual partitions separated by commas, for example: WITH (PARTITIONS (1, 5)) Provide both ranges and individual partitions, for example: WITH (PARTITIONS (2, 4, 6 TO 8)) <range> can be specified as partition numbers separated by the word TO, for example: WITH (PARTITIONS (6 TO 8))

例子:

TRUNCATE TABLE dbo.PartitionedTable WITH (PARTITIONS (2, 4, 6 TO 8))

2016 年之前的 SQL Server

今天你可以使用這個

正如您所注意到的,今天有一種方法可以通過ALTER TABLE SWITCH將分區移動到第二個表,然后截斷第二個表。 如果兩個表都是同一個文件組的一部分,這實際上應該是一個低風險的操作,因為沒有數據被移動,我們只是更新元數據。

表開關示例

我會說從 table_name 中刪除 *。 從表中刪除所有內容。 您可以在刪除后使用 where 語句更精確。 自己調整命令看這里http://www.w3schools.com/sql/sql_between.asp

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM