INSERT row size limit exceeded

INSERT row size limit exceeded

Post by Dai » Thu, 17 Apr 2003 12:46:01



I seem to have hit a bug with a table with an nvarchar
(4000) column and a couple of other columns totalling 50
bytes.  Although this is less than the allowed 8060 data
limit and enterprise manager does not complain, when later
inserting a row with 4000 chars I get the error

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

The data being inserted does not exceed this limit (it
should be no more than 8050 bytes).  I have found a thread
on another forum that suggest this occurs when SQL Server
creates a temp table to hold the inserted data, but does
anyone have more information and/or a workaround that does
not involve decreasing the column size?

TIA,

Dai

 
 
 

INSERT row size limit exceeded

Post by Jobi » Thu, 17 Apr 2003 13:47:02


post your create table ddl.

Maybe then we can help
jobi

Quote:> I seem to have hit a bug with a table with an nvarchar
> (4000) column and a couple of other columns totalling 50
> bytes.  Although this is less than the allowed 8060 data
> limit and enterprise manager does not complain, when later
> inserting a row with 4000 chars I get the error

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

> The data being inserted does not exceed this limit (it
> should be no more than 8050 bytes).  I have found a thread
> on another forum that suggest this occurs when SQL Server
> creates a temp table to hold the inserted data, but does
> anyone have more information and/or a workaround that does
> not involve decreasing the column size?

> TIA,

> Dai


 
 
 

INSERT row size limit exceeded

Post by Dan Guzma » Thu, 17 Apr 2003 15:22:46


In addition to the defined data size, you need to consider row and
column overhead.  See the SQL Server 2000 Books Online
<createdb.chm::/cm_8_des_02_92k3.htm> for details on calculating row
size.

SQL Server will return a warning when the max row size may potentially
be exceeded but Enterprise Manager might not report this.  I ran the
following script in Query Analyzer and got the warning message.

CREATE TABLE MyTable
    (
    MyPK bigint NOT NULL
        CONSTRAINT PK_MyTable PRIMARY KEY,
    MyColumn1 nvarchar(21) NOT NULL,
    MyColumn2 nvarchar(4000) NOT NULL
    )

If your row length may exceed 8060 bytes, you have a couple of options.

1)  Split data into multiple tables:

    CREATE TABLE MyTable1
        (
        MyPK bigint NOT NULL
            CONSTRAINT PK_MyTable1 PRIMARY KEY,
        MyColumn1 nvarchar(21) NOT NULL
    )

    CREATE TABLE MyTable2
        (
        MyPK bigint NOT NULL
            CONSTRAINT PK_MyTable2 PRIMARY KEY,
        MyColumn2 nvarchar(4000) NOT NULL
        )

    CREATE View MyTable
    AS
    SELECT t1.MyPK, t1.MyColumn1, t2.MyColumn2
    FROM MyTable1 t1
    JOIN MyTable2 t2 ON
        t2.MyPK = t1.MyPK

2)  Use ntext instead of nvarchar to move the data off of the row:

    CREATE TABLE MyTable
        (
        MyPK bigint NOT NULL
            CONSTRAINT PK_MyTable PRIMARY KEY,
        MyColumn1 nvarchar(21) NOT NULL,
        MyColumn2 ntext NOT NULL
        )
       EXEC sp_tableoption 'MyTable', 'text in row', 3000

There are additional considerations with ntext.  See the Books Online
for more info.

--
Hope this helps.

Dan Guzman
SQL Server MVP

-----------------------
SQL FAQ links (courtesy  Neil Pike):

http://www.ntfaq.com/Articles/Index.cfm?DepartmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
-----------------------


Quote:> I seem to have hit a bug with a table with an nvarchar
> (4000) column and a couple of other columns totalling 50
> bytes.  Although this is less than the allowed 8060 data
> limit and enterprise manager does not complain, when later
> inserting a row with 4000 chars I get the error

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

> The data being inserted does not exceed this limit (it
> should be no more than 8050 bytes).  I have found a thread
> on another forum that suggest this occurs when SQL Server
> creates a temp table to hold the inserted data, but does
> anyone have more information and/or a workaround that does
> not involve decreasing the column size?

> TIA,

> Dai

 
 
 

INSERT row size limit exceeded

Post by Dai William » Thu, 17 Apr 2003 17:28:35


Dan,

That is perfect, I am actually ok with dropping the column size a little
but I wanted to be sure that the row length was not data dependent
(given that it is a 4000 char string) or dependent on anything else that
may change

Now it is something I can calculate with confidence rather than just
drop the field size a little and cross my fingers.
Thanks,

Dai

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

 
 
 

INSERT row size limit exceeded

Post by Dan Guzma » Fri, 18 Apr 2003 15:43:55


Glad it helped.

--
Dan Guzman
SQL Server MVP


Quote:> Dan,

> That is perfect, I am actually ok with dropping the column size a
little
> but I wanted to be sure that the row length was not data dependent
> (given that it is a 4000 char string) or dependent on anything else
that
> may change

> Now it is something I can calculate with confidence rather than just
> drop the field size a little and cross my fingers.
> Thanks,

> Dai

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

 
 
 

1. Worktable row size exceeding limits

Hi,

I am running the following query.

SELECT a.Diagnostics, a.Template, sum(a.Count) as total,
count(distinct(a.RemoteAddress)) as iptotal, max(a.DateTime) as Last,
min(b.ID) as eid
FROM applog a, applog b
WHERE a.DateTime between dateadd(d, 0, '02/22/2002') AND dateadd(d, 1,
'02/22/2002') AND a.Diagnostics LIKE '%ada%' AND a.Diagnostics =
b.Diagnostics GROUP BY a.Diagnostics, a.Template ORDER BY Last DESC

This query give the error
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot create a
worktable row larger than allowable maximum. Resubmit your query with
the ROBUST PLAN hint.

diagnostics is a varchar(3000)
template is a varchar(255)
The other columns are int, datetime, and varchar(15), nothing that
big.

I don't see how the rows in this query exceed 8k.

What columns for this query will the worktable have?  would they only
consist of the columns anywhere in the entire query, or only in the
group by clause or only in the order by clause, or would the worktable
have all of the columns in the two tables in this query?

The applog table consists of 15 columns broken down as the following.
1 - varchar(3000)
5 - varchar (255)
2 - text
1 - datetime
2 - int
2 - bit
1 - varchar(15)
1 - char(1)

Thanks for your help!
Dan

2. problems using BCP and 'image' fields

3. Error message i SQL Server Log

4. exceeding total row size limit

5. 14072-MO-KANSAS CITY-ORACLE-DBA Skills-Database Administrator

6. exceed row size limit?

7. Expressions Across Multiple Fact Tables

8. Row size exceeds max size

9. ODBC Driver error 80040e14 Row exceed maximum allowed row size

10. Row size could exeed size limit, wich iss 1962 bytes

11. ulimit question....getting file exceeds file size limit

12. "Warning: Row size (4068 bytes) could exceed row size limit, which is 4012"