简体   繁体   English

有没有办法从分区表中删除范围值(sql server 2012)

[英]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.如果两个表都是同一个文件组的一部分,这实际上应该是一个低风险的操作,因为没有数据被移动,我们只是更新元数据。

Example TABLE SWITCH 表开关示例

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.

相关问题 在SQL Server 2012中创建具有日期作为范围分区的表 - Creating a table with date as range partition in SQL Server 2012 如何从SQL Server 2012中的表的一个分区获取COUNT(*)? - How to get COUNT(*) from one partition of a table in SQL Server 2012? 在 ROW_NUMBER() 和 PARTITION BY | 中读取 0.5 值 SQL 服务器 2012 - Reading 0.5 value in ROW_NUMBER() and PARTITION BY | SQL Server 2012 如何从SQL Server 2012中的表列查询最大值? - How to query highest value from table column in SQL Server 2012? 更改表分区中的范围值 - Change range value in table partition SQL Server 2012-找不到分区ID为xxxxx的表或索引的条目 - SQL Server 2012 - Could not find an entry for table or index with partition ID xxxxx 是否可以基于sql server中的列值在表中创建分区? - Can I create a partition in table based on column value in sql server? SQL Server 2012-从不同的值为不同的记录集分配递增编号的最佳方法 - SQL Server 2012 - Best way to assign incrementing number for differing sets of records, from a specific value 有没有办法告诉表SQL Server 2012中修改表的最后日期 - Is there a way to tell the last date time a table was modified in SQL Server 2012 在SQL Server 2012 Express上执行表压缩算法的最佳方法 - Best way to execute table compaction algorithm on SQL Server 2012 Express
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM