November 2, 2009 at 9:24 pm
Can anyone pls help me on how to find the actual space occupied by a row in a table
November 3, 2009 at 3:55 am
you can use DATALENGTH function.
SELECT ISNULL(DATALENGTH ([COL0]),0) + ISNULL(DATALENGTH ([COL1]),0) + .... FROM
....
you can add the key column's at the begin to know witch row is...
see post http://www.sqlservercentral.com/Forums/Topic226699-5-1.aspx
Pedro
November 3, 2009 at 5:31 am
This is about the 3rd time this question has been asked in as many days... why do you need to know this?
--Jeff Moden
Change is inevitable... Change for the better is not.
November 3, 2009 at 6:18 am
Jeff Moden (11/3/2009)
This is about the 3rd time this question has been asked in as many days... why do you need to know this?
homework questions, you think? trying to make people use built in functions?
Lowell
November 3, 2009 at 7:36 am
Why the need to know this?
Easy, we have a CRM database and each customer pays the space they use. They pay a fixed fee that gives them xGB of info, over that they have to pay extra.
Pedro
November 3, 2009 at 8:00 am
What I think you'd want to do is calculate the sizes of all rows that you have in the db, for all tables, and give that to the customers as an estimate of space.
500 contacts = xx kb
200 phone numbers = yy kb
...
Then for the actual customer, are you going to go on actual bytes used by data or bytes used by the tables? They are two different things. varchars have some overhead against the row size, not much, but there is overhead. Fillfactor affects space use, you might lower is for resource intensive usage, etc.
I'd be careful about how you word this and charge people.
November 3, 2009 at 8:06 am
Can't do that "big picture" since our customers share the same tables on the same databases.
It's a very "heavy" process that runs every week, to give an average at the end of the month.
Besides DATALENGTH() is there any other function, like ROWSIZE() or something?! 😀 That would be nice :D...
Pedro
November 3, 2009 at 6:35 pm
Ah... thanks for the feedback on what you actually need it for. It's a rare pleasure to get that kind of feedback.
I'm in the process of rebuilding my computer (obviously, I have the internet connection working again, finally) and I haven't reinstalled SQL Server yet so I can write some tested demo code BUT... why not use sp_SpaceUsed so you can include the total size of the table including indexes and the like, count the total number of rows and the number of rows for each customer and do the simple math from there?
--Jeff Moden
Change is inevitable... Change for the better is not.
November 3, 2009 at 9:22 pm
Or - use the reports and get all tables at the same time, broken down by type of space, (break it out by partition if you like), with an option to export the results to excel, etc...
Table Name# RecordsReserved (KB)Used (KB)
dbo.MattTest14,000,000266,672266,480
Index (PK__MattTest__4B5BD7F80519C6AF)4,000,000163,080163,056
Index (MattTest1_UCI) 4,000,000103,592103,424
dbo.tally1,000,00012,93612,920
Index (PK__tally__3BD019B300551192)1,000,00012,93612,920
dbo.tally21,000,00016,84816,824
Table 1,000,00016,84816,824
I know I know, not sexy in a command-line kind of way.....:)
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply