繁体   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