Home / Programming / Blog article: SQL Server – sp_spaceused Use The Right Way

| RSS

SQL Server – sp_spaceused Use The Right Way

March 19th, 2009 | No Comments | Posted in Programming

To find out the space used by a table we can use sp_spaceused procedure. Most of the times sp_spaceused will give correct information. Why do I say most of the time? Well consider this example. I just inserted a large amount of data in Orders table in Northwind database and ran sp_spaceused.

EXEC sp_spaceused 'Orders'

which returns this result

image

But if I run sp_spaceused with true for its second parameter which is updateusage

EXEC sp_spaceused 'Orders', TRUE

I get the following result

image

Notice the difference in reserved space and index size. What has happened here is that by passing in true for updateusage SQL Server automatically runs DBCC UPDATEUSAGE which corrects any inaccuracies in catalog views. So it is a good idea to run sp_spaceused by supplying true for updateusage parameter if you absolutely must get accurate information. And especially after inserting large amounts of data.

Leave a Reply 3381 views, 1 so far today |
Tags:

Leave a Reply





Switch to our mobile site