• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

Calc space used by a client

I "sell" database storage space in a table called TABX. At one extreme, a customer can chose to store 1 small record in TABX, or (at the other extreme) store a million records each containing a 1gigabyte BLOB. Of course the average is more like 200 records with a dozen or so BLOBS.

Once per night, I need a uniform way of calculating approximate storage space used per client. So I can bill for space used ....

For discussion, let's say TABX is ...

          CREATE TABLE dbo.TABX
          (
                    ClientID int NOT NULL,
                    ItemID int NOT NULL IDENTITY (1, 1),
                    Fi image NULL,
                    Ft text NULL,
                    Fv varchar(8000) NULL
          )  ON [PRIMARY]
           TEXTIMAGE_ON [PRIMARY]

Any suggestions on how to approach this problem?
Using SQL Server Ver 8.0
0
volking
Asked:
volking
  • 3
  • 3
  • 2
  • +3
4 Solutions
 
ptjcbCommented:
You could run sp_spaceused against each database.

exec sp_spaceused

FROM BOL:
Displays the number of rows, disk space reserved, and disk space used by a table, indexed view, or SQL Server 2005 Service Broker queue in the current database, or displays the disk space reserved and used by the whole database.

0
 
SjoerdVerweijCommented:
Have you tried

Select ClientID, Sum(DataLength(Fi)), Sum(DataLength(Ft)), Sum(DataLength(Fv))
From TabX
Group By ClientID
0
 
Scott PletcherSenior DBACommented:
This should give you a decent approx., although it may not be exact:


SELECT ClientID, SUM(4 /*ClientID*/ + 4 /*ItemID*/ +
    16 + DATALENGTH(Fi) /*Fi*/ + 16 + DATALENGTH(Ft) /*Ft*/ + DATALENGTH(Fv) + 2 /*Fv*/ +
    2 /*varchar row overhead */ + 10 /*general row overhead*/)
    AS [Total Bytes Used (Approx.)]
FROM TabX
GROUP BY ClientID
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Aneesh RetnakaranDatabase AdministratorCommented:
this article will give you the exact size

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/createdb/cm_8_des_02_92k3.asp


Again you need to find out how many no of rows inserted / day
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
minimum space / row =  4B + 4B+ 4KB + 4kb +8000
                                 nearly 16kb

for text/image columns min size is 4k
0
 
SjoerdVerweijCommented:
Personally, I'd stick with DataLength... I've done a similar thing before, and trust me, the LAST thing you want to do is explain Scott's approximation. Actually, the truth is even worse, with a nullability bitmask, and then figuring how many of that type of record (excluding the blob fields) fits in a single 8KB page (-standard page overhead), since records do not straddle a page, then for non-null BLOB columns, the greater of a single page or the contents (assuming you have text_in_row off, of course)....

*Thud*
0
 
LowfatspreadCommented:
i agree with sjoerdverweij go with the datalength and have variable charging rates with a min per month fee...
0
 
volkingAuthor Commented:
For my purposes, approximate is "good-enough"

So to get total volume, I'll use
     exec sp_spaceused
then I'll run something like
     Select ClientID, Sum(DataLength(Fi)), Sum(DataLength(Ft)), Sum(DataLength(Fv)) From TabX Group By ClientID

and finally I'll use a RATIO of total volume divided by each clients total, should be close enough for my use.

Smallest charge is 100mb segments so above ratio should be close enough (and I'll be able to explain it ... grin)

Thank All
Volking
0
 
Scott PletcherSenior DBACommented:
Personally I don't see why it's so hard to explain that an integer takes 4 bytes, etc..

I was trying to answer your original q, in which you stated that a person might have *1* row only.  Thus I thought you needed to be fairly accurate.  If I'd known you just wanted to get within 100MB (! -- *nowhere close to just one row*), I'd have saved myself the effort of writing and you all the effort of reading it.
0
 
SjoerdVerweijCommented:
Scott, it goes much further than that -- nullability, how many rows fit on a page (for some record sizes, almost 4K - 50% can be wasted), etc. etc.  You're pretty much explaining the entire SQL Server storage architecture if you want to be accurate.
0
 
Scott PletcherSenior DBACommented:
Of course ... I was trying to determine the *minimum* space that could be used.  Page overhead would be extremely difficult to allocate anyway.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now