错误:将XSD与XML数据类型列关联 - “无法创建一行大小”

时间:2014-04-30 07:48:54

标签: sql sql-server sql-server-2005

我在将XSD与表格中的XML数据类型列关联时遇到以下错误。

"Cannot create a row of size XXXX which is greater than the allowable maximum of 8060" 

以下是SQL语句:

ALTER TABLE PPHGrader_PreferenceData ALTER COLUMN Pref_Data XML ([dbo].[PrefDataSchemaInstrEdit]);

这是什么原因以及解决方法是什么? 谢谢。

1 个答案:

答案 0 :(得分:3)

您的表已接近8060的限制。添加BLOB列(如XML类型)需要另外24个字节并将其推过此限制。请参阅SQL Server table columns under the hood以了解发生的情况并获取一些查询以查看物理表布局:

select p.index_id, p.partition_number,
    pc.leaf_null_bit,
    coalesce(cx.name, c.name) as column_name,
    pc.partition_column_id,
    pc.max_inrow_length,
    pc.max_length,
    pc.key_ordinal,
    pc.leaf_offset,
    pc.is_nullable,
    pc.is_dropped,
    pc.is_uniqueifier,
    pc.is_sparse,
    pc.is_anti_matter
from sys.system_internals_partitions p
join sys.system_internals_partition_columns pc
    on p.partition_id = pc.partition_id
left join sys.index_columns ic
    on p.object_id = ic.object_id
    and ic.index_id = p.index_id
    and ic.index_column_id = pc.partition_column_id
left join sys.columns c
    on p.object_id = c.object_id
    and ic.column_id = c.column_id
left join sys.columns cx
    on p.object_id = cx.object_id
    and p.index_id in (0,1)
    and pc.partition_column_id = cx.column_id
where p.object_id = object_id('PPHGrader_PreferenceData')
order by index_id, partition_number;

如果你很幸运,那么一些空间来自掉落的列,在这种情况下你可以重建表来摆脱那个空间并再试一次。如果您确实使用了每行近8060字节并且没有占用空间的列,那么您需要减小尺寸:

  • 将固定长度列CHAR / NCHAR / BINARY更改为可变长度类型VARCHAR / NVARCHAR / VARBINARY
  • 规范化对象模型以减少属性数量
  • 如果仍然需要每行更多的空间,use SPARSE columns