Sql-Server

明顯錯誤的 Exceeds 8K row length 消息

  • May 13, 2020

在嘗試更改添加 DATE 和 FLOAT 列的 SQL Server 表時。我收到一條消息:

警告:已創建表“CustomerTransactions”,但其最大行大小超過了允許的最大值 8060 字節。如果結果行超過大小限制,則對該表的 INSERT 或 UPDATE 將失敗。

我知道 8K 的限制,但是我很難過,因為該表不超過 8K。

DDL 和故障在下面粘貼。不知道在哪裡進一步尋找。有什麼建議嗎?

更改表:

           ALTER TABLE [dbo].[CustomerTransactions] 
           ADD 
               NumericDate FLOAT,
               FirstDayOfWeek DATE,
               LastDayOfWeek DATE,
               NFirstDayOfWeek FLOAT,
               NLastDayOfWeek FLOAT,
               FirstDayOfMonth DATE,
               LastDayOfMonth DATE,
               NFirstDayOfMonth FLOAT,
               NLastDayOfMonth FLOAT,
               HalfMonthStart DATE,
               HalfMonthEnd DATE,
               NHalfMonthStart FLOAT,
               NHalfMonthEnd FLOAT,
               HalfOfMonth INT,
               FirstDayOfQuarter DATE,
               LastDayOfQuarter DATE,
               NFirstDayOfQuarter FLOAT,
               NLastDayOfQuarter FLOAT,
               FirstDayOfYear DATE,
               LastDayOfYear DATE,
               NFirstDayOfYear FLOAT,
               NLastDayOfYear FLOAT

系統列總數

select count(*) NumCols, SUM(sc.length) SumLength
from syscolumns sc  
inner join systypes st on sc.xtype = st.xtype  
where id = object_id('CustomerTransactions')

NumCols SumLength
------- ---------
64      4463

系統列分解

select sc.name, st.name, sc.length
from syscolumns sc
left join systypes st
on sc.xtype = st.xtype
where id = object_id('CustomerTransactions')

name                      name                  length
------------------------  --------------------  -------
RowType                   varchar                   40
ReportCategory            varchar                   255
Date                      date                      3
TxnId                     varchar                   26
TxnType                   varchar                   255
AccountId                 varchar                   36
AccountType               varchar                   21
Account                   varchar                   255
AccountNameLong           varchar                   159
Amount                    decimal                   9
Reference                 varchar                   255
AmountPastDue             decimal                   9
AmountDue                 decimal                   9
Rep                       varchar                   255
RepRegion                 varchar                   255
RepLevel1                 varchar                   255
Memo                      varchar                   -1
Phone                     varchar                   20
CustomerName              varchar                   255
CustomerAccountNumber     varchar                   255
PaidStatus                varchar                   255
LastPaymentDate           date                      3
LastPaymentType           varchar                   255
LastPaymentAmount         decimal                   9
ReferenceNumber           varchar                   20
Referal                   varchar                   255
ReferalNotes              varchar                   255
PurchaseNumber            int                       4
TotalPurchase             decimal                   9
AccountHierarchyL1        varchar                   50
AccountHierarchyL2        varchar                   50
AccountHierarchyL3        varchar                   50
AccountHierarchyL4        varchar                   50
AccountHierarchyL5        varchar                   50
AccountOtherDisplayValue  varchar                   50
ReportHeader1             varchar                   50
ReportHeader2             varchar                   50
ReportHeader3             varchar                   50
ReportHeader4             varchar                   50
ReportHeader5             varchar                   50
ReportHeader6             varchar                   50
ReportHeader7             varchar                   50
NumericDate               float                     8
FirstDayOfWeek            date                      3
LastDayOfWeek             date                      3
NFirstDayOfWeek           float                     8
NLastDayOfWeek            float                     8
FirstDayOfMonth           date                      3
LastDayOfMonth            date                      3
NFirstDayOfMonth          float                     8
NLastDayOfMonth           float                     8
HalfMonthStart            date                      3
HalfMonthEnd              date                      3
NHalfMonthStart           float                     8
NHalfMonthEnd             float                     8
HalfOfMonth               int                       4
FirstDayOfQuarter         date                      3
LastDayOfQuarter          date                      3
NFirstDayOfQuarter        float                     8
NLastDayOfQuarter         float                     8
FirstDayOfYear            date                      3
LastDayOfYear             date                      3
NFirstDayOfYear           float                     8
NLastDayOfYear            float                     8

這可能是由於之前的更改(尤其是現有列寬)仍然反映在底層頁面結構中。嘗試重建表或刪除/重新創建聚集索引以回收該空間。

引用自:https://dba.stackexchange.com/questions/74198