Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Calculate row length of table(s)


Calculate row length of table(s)

Author
Message
kns
kns
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 1
Comments posted to this topic are about the item Calculate row length of table(s)



vm.bharathiraja
vm.bharathiraja
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 12
What is row length of table?
is that mean the size of the row?
sscnn
sscnn
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 65
A bit of modifications to take care of schemas


SET quoted_identifier ON

GO

CREATE PROCEDURE [dbo].[usp_find_row_lenght]
(
@schema_name VARCHAR(100)=''
,@table_name VARCHAR(100)=''
)
AS
BEGIN
SET nocount ON

IF @table_name=''
OR @schema_name=''
BEGIN
SELECT
ss.name AS schema_name,
o.name AS table_name,
SUM(c.length) AS row_lenght
FROM
sysobjects o
INNER JOIN syscolumns c
ON o.id=c.id
INNER JOIN sys.objects so
ON o.id=so.object_id
INNER JOIN sys.schemas ss
ON so.schema_id=ss.schema_id
WHERE (o.xtype='u')
AND (o.type='u')
GROUP BY
o.name,
ss.name
ORDER BY
ss.name,
o.name
END
ELSE
BEGIN
SELECT
ss.name AS schema_name,
o.name AS table_name,
SUM(c.length) AS row_lenght
FROM
sysobjects o
INNER JOIN syscolumns c
ON o.id=c.id
INNER JOIN sys.objects so
ON o.id=so.object_id
INNER JOIN sys.schemas ss
ON so.schema_id=ss.schema_id
WHERE (o.xtype='u')
AND (o.type='u')
AND o.name=@table_name
AND ss.name=@schema_name
GROUP BY
o.name,
ss.name
ORDER BY
ss.name,
o.name
END
END

GO


sscnn
sscnn
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 65
vm.bharathiraja (8/25/2009)
What is row length of table?
is that mean the size of the row?

It's sum of the lenght of the fields in a row in bytes. It's not however the actual size of each of row, as that depends on other things besides the filed lenght.
Preethiviraj Kulasingham
Preethiviraj Kulasingham
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 86
This script does not consider the row overhead involved over variable columns, nullable columns and bit columns. I believe ( not tested though) about calculated columns were also not considered here.
Other than these issues, this script will give the sum of all bytes needs for the row itself.

Cheers,
Prithiviraj Kulasingham

Plan to Test your Plan!
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