Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Computing the 8060 row-size 1

Status
Not open for further replies.

harebrain

MIS
Feb 27, 2003
1,146
US
Is there a stored procedure that will compute the [maximum] size of a table's rows? It seems like that would be handy to know before altering a table.
 
Denis,

I'm confused. I came up with this query.

Code:
[COLOR=blue]Select[/color] Information_Schema.Columns.Table_Name, 
       Sum([COLOR=#FF00FF]Length[/color]) [COLOR=blue]As[/color] TotalDefinedLength
[COLOR=blue]From[/color]   syscolumns
       [COLOR=blue]Inner[/color] [COLOR=blue]Join[/color] Information_Schema.Columns
          [COLOR=blue]On[/color] [COLOR=#FF00FF]Object_Name[/color](syscolumns.id) = Information_Schema.Columns.Table_Name
          And syscolumns.Name = Information_Schema.Columns.Column_Name
[COLOR=blue]Group[/color] [COLOR=blue]By[/color] Information_Schema.Columns.Table_Name
[COLOR=blue]Order[/color] [COLOR=blue]By[/color] Information_Schema.Columns.Table_Name

The problem is... I'm getting different values. I think my query will tell you the maximum defined size, whereas yours will tell you the maximum used size. What do you think?

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
>> True, here is something to think about

I'm thinking that my query returns the correct number.

When I open the table in enterprise manager, I get...

[tt]
ColumnName Data Type Length
---------- --------- ------
col1 Decimal 9
col2 nvarchar 15
col3 float 8
[/tt]

Since it takes 2 bytes to store nvarchar character, the storage size is 30 for col2. So you end up with...

9 + 30 + 8 which is 47.

When I run my query, I get

[tt]
Table_Name TotalDefinedLength
---------- ------------------
testLenTable 47
[/tt]

Which appears to be correct. Am I missing something here?

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Now dont forget that every 8 nullable column's adds 1 bite and varchar fields add around 2 then there is the rowheadder (2 0r 4 bites), and the page headder..32 bites
so.. Add the extra overhad associated with nullable fileds and varchar.. + the row headder and then subtract 32 bites from the 8k page and you get close to gestimating how many rows will fit on a page.




 
Thanks guys!

I was trying to see what my ceiling was. I'm aware of the overhead bytes, but I'm not trying to wring out every last bit; a good ballpark figure is what I was looking for.

George, I thought that info had to be somewhere. I was thinking along those lines, and fortunately we're not (almost never) worried about wide chars.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top