[英]Is there a way to drop a range value from a partition table (sql server 2012)
I have a PARTITION table "TableA".我有一个分区表“TableA”。 I created a partition on column name "RecorDate" (DATE type).我在列名“RecorDate”(日期类型)上创建了一个分区。 There are records from the last 6 months that I am not interested to save them, and I want to drop them.有过去 6 个月的记录,我不想保存它们,我想删除它们。
Is there a simple way to drop a range vale OR specific partition number (or even a all range, for example '01-01-2014' to '01-01-2015').是否有一种简单的方法可以删除范围值或特定分区号(甚至是所有范围,例如“01-01-2014”到“01-01-2015”)。
something like in ORACLE, TRUNCATE TABLE WITH(PARTITION(x,y to z))
.类似于在 ORACLE 中, TRUNCATE TABLE WITH(PARTITION(x,y to z))
。
BTW I know the switch partition command, to move the range to another table and then exec the command顺便说一句,我知道 switch partition 命令,将范围移动到另一个表,然后执行该命令
TRUNCATE TABLE TableNameb ;
GO
10X 10倍
TRUNCATE WITH PARTITION will be available with SQL Server 2016 TRUNCATE WITH PARTITION将在 SQL Server 2016 中可用
WITH ( PARTITIONS ( { | } [ , ...n ] ) ) 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
will generate an error.会产生错误。 If the WITH PARTITIONS clause is not provided, the entire table will be truncated.如果未提供 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))
Example:例子:
TRUNCATE TABLE dbo.PartitionedTable WITH (PARTITIONS (2, 4, 6 TO 8))
SQL Server before 2016 2016 年之前的 SQL Server
Today you can use 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.正如您所注意到的,今天有一种方法可以通过ALTER TABLE SWITCH将分区移动到第二个表,然后截断第二个表。 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.如果两个表都是同一个文件组的一部分,这实际上应该是一个低风险的操作,因为没有数据被移动,我们只是更新元数据。
i would say delete * from table_name.我会说从 table_name 中删除 *。 delete all from table.从表中删除所有内容。 you can use the where statement after delete to be more precise.您可以在删除后使用 where 语句更精确。 to adjust the command yourself look here http://www.w3schools.com/sql/sql_between.asp自己调整命令看这里http://www.w3schools.com/sql/sql_between.asp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.