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]

Any suggestions on how to approach this problem?
Using SQL Server Ver 8.0
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You could run sp_spaceused against each database.

exec sp_spaceused

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.

Have you tried

Select ClientID, Sum(DataLength(Fi)), Sum(DataLength(Ft)), Sum(DataLength(Fv))
From TabX
Group By ClientID
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.)]
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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

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

for text/image columns min size is 4k
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)....


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
i agree with sjoerdverweij go with the datalength and have variable charging rates with a min per month fee...
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
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.
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.
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.