我正在使用SQL Server 2008。我有两个结构、分区模式/函数和相同文件组的 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
我收到错误
更改表切换失败。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 的分区:
将表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
)