Sql server 目标表分区为空,但alter table开关仍然无法声明目标分区必须为空
我正在使用SQL Server 2008。我有两个100个分区表,它们的结构、分区模式/功能和文件组都相同 表结构:Sql server 目标表分区为空,但alter table开关仍然无法声明目标分区必须为空,sql-server,database,sql-server-2008,Sql Server,Database,Sql Server 2008,我正在使用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
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\u表
有记录,但分区23为空。我需要将分区23记录从源表
移动到目标表
ALTER TABLE Source_table
SWITCH partition 23 TO Destination_table partition 23
我犯了一个错误
ALTER TABLE开关失败。目标_表的目标分区23必须为空
destination_table
的分区23已为空
Select count(1)
from destination_table
返回0
那么为什么会出现此错误?在分区值和分区Id之间存在混淆。分区值是23,但分区Id是24,因为分区值从0到99开始,分区Id是1到100 因此,分区Id 24用于移动值为23的分区:
将表源表切换分区24更改为目标表分区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
)