由于源表和目标表的文件组不匹配而导致交换分区失败
我想在其中一个表上实现交换机分区,并且确保分区函数,方案,文件组正常工作。但是当我运行下面的命令时,我得到文件组错误。有人可以分享你的想法。由于源表和目标表的文件组不匹配而导致交换分区失败
命令: -
ALTER TABLE XYZ SWITCH PARTITION 5 TO ABC PARTITION 5;
错误: -
ALTER TABLE switch语句失败。表'XYZ'在文件组'PRIMARY'中,表'ABC'的分区5在文件组'FG_5'中。
回答:
某些集群索引可能会在现有表上创建。因此,在可能不同的表上创建群集索引期间会提到文件组。或者如果你可以删除ABC表并重新创建并尝试你的查询。
查询检查表和索引名称的文件组。
select f.name,o.name,i.name from sys.indexes i inner join sys.filegroups f on i.data_space_id=f.data_space_id inner join sys.all_objects o on o.object_id= i.object_id
where o.name in ('ABC','XYZ')
我不会说这是解决方案,但这应该有助于解决问题。
回答:
该错误指示源表和目标表不存储对齐。运行下面的查询以确保源文件组和目标文件组在表和索引中都相同:
SELECT OBJECT_NAME(p.object_id) AS ObjectName,
i.name AS IndexName,
p.index_id AS IndexID,
ds.name AS PartitionScheme,
p.partition_number AS PartitionNumber,
fg.name AS FileGroupName,
prv_left.value AS LowerBoundaryValue,
prv_right.value AS UpperBoundaryValue,
CASE pf.boundary_value_on_right WHEN 1 THEN 'RIGHT' ELSE 'LEFT' END AS PartitionFunctionRange,
p.rows AS Rows
FROM
sys.partitions AS p INNER JOIN
sys.indexes AS i ON i.object_id = p.object_id AND i.index_id = p.index_id INNER JOIN
sys.data_spaces AS ds ON ds.data_space_id = i.data_space_id INNER JOIN
sys.partition_schemes AS ps ON ps.data_space_id = ds.data_space_id INNER JOIN
sys.partition_functions AS pf ON pf.function_id = ps.function_id INNER JOIN
sys.destination_data_spaces AS dds2 ON dds2.partition_scheme_id = ps.data_space_id AND dds2.destination_id = p.partition_number INNER JOIN
sys.filegroups AS fg ON fg.data_space_id = dds2.data_space_id LEFT OUTER JOIN
sys.partition_range_values AS prv_left ON ps.function_id = prv_left.function_id AND prv_left.boundary_id = p.partition_number - 1 LEFT OUTER JOIN
sys.partition_range_values AS prv_right ON ps.function_id = prv_right.function_id AND prv_right.boundary_id = p.partition_number
WHERE
p.object_id IN (
OBJECT_ID(N'dbo.ABC')
, OBJECT_ID(N'dbo.XYZ')
)
AND p.partition_number = 5
ORDER BY
ObjectName
,IndexName
,PartitionNumber;
以上是 由于源表和目标表的文件组不匹配而导致交换分区失败 的全部内容, 来源链接: utcz.com/qa/257884.html