SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQL >> Cannot sort a row of size 8096[...]


SQL >> Cannot sort a row of size 8096[...]

Author
Message
Warlockzzz
Warlockzzz
Valued Member
Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)

Group: General Forum Members
Points: 61 Visits: 1

Hi,

I have a strange error in one of the query that I am doing. And, I am un-sure on how to resolve it. Here is the query :

SELECT o.name, c.number, c.colid, c.text
FROM
syscomments c
INNER JOIN sysobjects o ON c.id = o.id
WHERE
(o.xtype = 'P') AND (
(c.text LIKE '%a%')
OR
(o.name like '%a%')
 
ORDER BY
o.name,
c.number,
c.colid
Error Message :
Server: Msg 1540, Level 16, State1, Line 3
Cannot sort a row of size 8096, which is greater than the allowable maximum of 8094.
As far as i know, name seen to be of the type sysname, number is of type int and colid is also of type int. Those three togheter, if they are put together, can't go over the 8094 limit. I know that the biggest row is the text, length of 4k, yet, does SQL server take that row in consideration when he sort? Even though it is not specify inside the ORDER BY clause?
I might be missing something somewhere or maybe not. Tell me if you need more detail to help me solve or avoid this kind of error.
Thanks

john-132685
john-132685
SSCarpal Tunnel
SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)

Group: General Forum Members
Points: 4986 Visits: 1

(From what I know...)

Yes it includes the text (varchar) column. (even though you think it's 4k because of nvarchar it may be 2 bytes per position).

So, in order to do the order by it needs to move the data to a temp table and that's where it wants to choke. It may happen to work if you have an index that supports the order and filter (order by & where clauses).

The other way I've hacked around this is to convert the text column to varchar (from nvarchar) so that max length of all columns is under 8k, or if that fails, make assumptions on the text field that none is bigger than like 3k, and convert that one on select.

(like select a, b, convert(varchar(4000), t) from...)


Ninja's_RGR'us
Ninja's_RGR'us
SSC Guru
SSC Guru (262K reputation)SSC Guru (262K reputation)SSC Guru (262K reputation)SSC Guru (262K reputation)SSC Guru (262K reputation)SSC Guru (262K reputation)SSC Guru (262K reputation)SSC Guru (262K reputation)

Group: General Forum Members
Points: 262349 Visits: 9673
name is sysname(128) = 128
number and colid are smallint = 4
Text is nvarchar(4000) = 8000

So you can definitly bust the 8094 limit there. But as John suggested, you can convert the text to varchar (unless you use chinese text in there) and it'll go down 4000 characters.
Warlockzzz
Warlockzzz
Valued Member
Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)

Group: General Forum Members
Points: 61 Visits: 1

Done, and it worked.

Thanks to both of you guys.


D-239855
D-239855
SSC Rookie
SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)

Group: General Forum Members
Points: 39 Visits: 1

John,

Thanks for your solutions. I tried changed all my nvarchar to varch and the problem went away. Thanks a bunch.

Dom


Ninja's_RGR'us
Ninja's_RGR'us
SSC Guru
SSC Guru (262K reputation)SSC Guru (262K reputation)SSC Guru (262K reputation)SSC Guru (262K reputation)SSC Guru (262K reputation)SSC Guru (262K reputation)SSC Guru (262K reputation)SSC Guru (262K reputation)

Group: General Forum Members
Points: 262349 Visits: 9673
I stand corrected. Sysname is Nvarchar(128)... Just in case anyone reads this later on.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search