有没有办法从分区 table (sql server 2012) 中删除范围值
Is there a way to drop a range value from a partition table (sql server 2012)
我有一个分区 table "TableA"。
我在列名 "RecorDate"(DATE 类型)上创建了一个分区。
有最近 6 个月的记录,我不想保存它们,我想删除它们。
是否有一种简单的方法来删除范围值或特定分区号(甚至是所有范围,例如“01-01-2014”到“01-01-2015”)。
类似于 ORACLE 中的东西,TRUNCATE TABLE WITH(PARTITION(x,y to z))
。
顺便说一句
我知道 switch partition 命令,将范围移动到另一个 table 然后执行命令
TRUNCATE TABLE TableNameb ;
GO
10X
我会说从 table_name 中删除 *。从 table 中删除所有内容。
您可以在 delete 之后使用 where 语句来更精确。
自己调整命令看这里 http://www.w3schools.com/sql/sql_between.asp
TRUNCATE WITH PARTITION 将在 SQL Server 2016
中可用
WITH ( PARTITIONS ( { | } [ ,
...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
will generate an error. If the WITH PARTITIONS clause is not provided,
the entire table will be truncated.
<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))
SQL 2016年以前的服务器
今天你可以使用 this:
As you note, there is a way to do this today by moving the partition to a second table through ALTER TABLE SWITCH and then TRUNCATE the second table. If both tables are part of the same filegroup, this should actually be a low-risk operation as no data is moved, we just update the metadata.
我有一个分区 table "TableA"。 我在列名 "RecorDate"(DATE 类型)上创建了一个分区。 有最近 6 个月的记录,我不想保存它们,我想删除它们。
是否有一种简单的方法来删除范围值或特定分区号(甚至是所有范围,例如“01-01-2014”到“01-01-2015”)。
类似于 ORACLE 中的东西,TRUNCATE TABLE WITH(PARTITION(x,y to z))
。
顺便说一句 我知道 switch partition 命令,将范围移动到另一个 table 然后执行命令
TRUNCATE TABLE TableNameb ;
GO
10X
我会说从 table_name 中删除 *。从 table 中删除所有内容。 您可以在 delete 之后使用 where 语句来更精确。 自己调整命令看这里 http://www.w3schools.com/sql/sql_between.asp
TRUNCATE WITH PARTITION 将在 SQL Server 2016
中可用WITH ( PARTITIONS ( { | } [ , ...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
will generate an error. If the WITH PARTITIONS clause is not provided, the entire table will be truncated.
<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))
SQL 2016年以前的服务器
今天你可以使用 this:
As you note, there is a way to do this today by moving the partition to a second table through ALTER TABLE SWITCH and then TRUNCATE the second table. If both tables are part of the same filegroup, this should actually be a low-risk operation as no data is moved, we just update the metadata.