[英]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.