2016-02-06 29 views
0

我正在使用SQL Server 2008.我有兩個100個分區表,它們的結構相同,分區架構/功能和相同的文件組。目標表分區爲空,但alter table switch仍然失敗,說明目標分區必須爲空

表結構:

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是空的。我需要將Source_table的分區23記錄移動到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

那麼爲什麼會出現這樣的錯誤?

回答

0

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

所以,分區ID 24曾與價值23移動分區:

ALTER TABLE Source_table SWITCH分區24 TO Destination_table分區24

相關問題