簡體   English   中英

目標表分區為空,但更改表切換仍然失敗,說明目標分區必須為空

[英]Destination table partition is empty but alter table switch still fails stating destination partition must be empty

我正在使用SQL Server2008。我有兩個具有相同結構,分區架構/功能和相同文件組的100個分區表。

表結構:

Create table source_table
(
     id int, 
     XmlData xml, 
     Partitionkey ([id]%(100)) As Persisted
)

Create table Destination_table
(
     id int, 
     XmlData xml, 
     Partitionkey ([id]%(100)) As Persisted
)

需求:

Destination_table有記錄,但分區23為空。 我需要將分區23記錄從Source_table移到Destination_table

ALTER TABLE Source_table 
SWITCH partition 23 TO Destination_table partition 23

我得到一個錯誤

ALTER TABLE SWITCH失敗。 Destination_table的目標分區23必須為空。

destination_table的分區23已經為空。

Select count(1) 
from destination_table 

返回0。

那為什么我會得到這個錯誤?

分區值和分區ID之間有混淆。 分區值為23,但分區ID為24,因為分區值從0到99開始,分區ID為1到100。

因此,分區ID 24用於移動值為23的分區:

ALTER TABLE Source_table切換分區24到Destination_table分區24

這種結構會起作用

Create table source_table
(
     id int, 
     XmlData xml, 
     Partitionkey ((([id] - 1) % (100)) + 1) As Persisted
)

Create table Destination_table
(
     id int, 
     XmlData xml, 
     Partitionkey ((([id] - 1) % (100)) + 1) As Persisted
)

暫無
暫無

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

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