最大行大小超过允许的最大值 8060 字节
Maximum row size exceeds the allowed maximum of 8060 bytes
在 运行 Microsoft SQL Server 2014 中。更改 table 后,我收到有关行大小的警告。
ALTER TABLE myTable
ALTER COLUMN aRandomColumn NVARCHAR(10);
Warning: The table "myTable" has been created, but its maximum row size exceeds the allowed maximum of 8060 bytes. INSERT or UPDATE to this table will fail if the resulting row exceeds the size limit.
table 有 75 列:
- 13 日
- 9位
- 8 整数
- 5 小数(18,5)
- 4 大整数
- 3 钱
- 19 nvarchar(10)
- 10 nvarchar(20)
- 1 nvarchar(30)
- 1 nvarchar(40)
- 2 nvarchar(50)
根据我的计算,nvarchar 占用 1120 个字节,其他列占用 121 个字节(不确定,但不会更多)。
这怎么超过了8060字节?我怎样才能摆脱这个警告?
尝试用 isnull(datalength(myColumnName), 1)
对所有列求和,实际数据从未超过 600。
找到 but change tracking is off for me, so it didn't help. Also cleantable, found in this question,没有帮助。
但是,当我复制 table 时,新的 table 不会产生此警告。
SELECT * INTO myNewTable FROM myTable;
-- (8561 row(s) affected)
ALTER TABLE myNewTable
ATLER COLUMN aRandomColumn NVARCHAR(10);
-- Command(s) completed successfully.
找到了我的问题的解决方案。
This question deals with the same issue, and points to the solution in another location.
This is likely due to previous alters (particularly of existing column
widths) that are still reflected in the underlying page structure. Try
rebuilding the table or dropping/re-creating the clustered index to
reclaim that space.
对我有用的是:
ALTER TABLE myTable
ADD CONSTRAINT pk_bigchange PRIMARY KEY (aColumnWithUniqueNonNullValues);
GO
ALTER TABLE myTable
DROP CONSTRAINT pk_bigchange;
GO
在 运行 Microsoft SQL Server 2014 中。更改 table 后,我收到有关行大小的警告。
ALTER TABLE myTable
ALTER COLUMN aRandomColumn NVARCHAR(10);
Warning: The table "myTable" has been created, but its maximum row size exceeds the allowed maximum of 8060 bytes. INSERT or UPDATE to this table will fail if the resulting row exceeds the size limit.
table 有 75 列:
- 13 日
- 9位
- 8 整数
- 5 小数(18,5)
- 4 大整数
- 3 钱
- 19 nvarchar(10)
- 10 nvarchar(20)
- 1 nvarchar(30)
- 1 nvarchar(40)
- 2 nvarchar(50)
根据我的计算,nvarchar 占用 1120 个字节,其他列占用 121 个字节(不确定,但不会更多)。
这怎么超过了8060字节?我怎样才能摆脱这个警告?
尝试用 isnull(datalength(myColumnName), 1)
对所有列求和,实际数据从未超过 600。
找到
但是,当我复制 table 时,新的 table 不会产生此警告。
SELECT * INTO myNewTable FROM myTable;
-- (8561 row(s) affected)
ALTER TABLE myNewTable
ATLER COLUMN aRandomColumn NVARCHAR(10);
-- Command(s) completed successfully.
找到了我的问题的解决方案。
This question deals with the same issue, and points to the solution in another location.
This is likely due to previous alters (particularly of existing column widths) that are still reflected in the underlying page structure. Try rebuilding the table or dropping/re-creating the clustered index to reclaim that space.
对我有用的是:
ALTER TABLE myTable
ADD CONSTRAINT pk_bigchange PRIMARY KEY (aColumnWithUniqueNonNullValues);
GO
ALTER TABLE myTable
DROP CONSTRAINT pk_bigchange;
GO