473,473 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

space used by a table?

I have a database that has grown larger than I had expected. I think
there is one table that is at the root of the problem. The table is
defined as follows:

CREATE TABLE [dbo].[UserAudit] (
[UserAudit_id] [int] IDENTITY (1, 1) NOT NULL ,
[UserAuditAction_id] [int] NOT NULL ,
[Dataset_id] [int] NOT NULL ,
[UserName] [char] (64) NOT NULL ,
[TableName] [char] (64) NOT NULL ,
[Detail] [varchar] (4000) NOT NULL ,
[DateRecorded] [smalldatetime] NOT NULL ,
[Dsc] [char] (256) NULL
)

There are 14919 records in this table. When I do the calculations i
approximate that space used by this table should be in the region of
10mb (4+4+4+64+64+290(average length of Detail column)+4+256) * 14919.

When I execute "sp_spaceused 'UserAudit'" i see that 119MB are being
used by this table.

name rows reserved data index_size unused
UserAudit 14919 119808 KB 119352 KB 400 KB 56 KB
Even if I use 4000 for the Detail column in my calculations I still
come up with about only 64mb.

Any ideas on whats going on here?
Thanks in advance.
Jul 20 '05 #1
6 5438

"Ruaidhri" <rg*****@polymorphia.com> wrote in message
news:76**************************@posting.google.c om...
I have a database that has grown larger than I had expected. I think
there is one table that is at the root of the problem. The table is
defined as follows:

CREATE TABLE [dbo].[UserAudit] (
[UserAudit_id] [int] IDENTITY (1, 1) NOT NULL ,
[UserAuditAction_id] [int] NOT NULL ,
[Dataset_id] [int] NOT NULL ,
[UserName] [char] (64) NOT NULL ,
[TableName] [char] (64) NOT NULL ,
[Detail] [varchar] (4000) NOT NULL ,
[DateRecorded] [smalldatetime] NOT NULL ,
[Dsc] [char] (256) NULL
)

There are 14919 records in this table. When I do the calculations i
approximate that space used by this table should be in the region of
10mb (4+4+4+64+64+290(average length of Detail column)+4+256) * 14919.

When I execute "sp_spaceused 'UserAudit'" i see that 119MB are being
used by this table.

name rows reserved data index_size unused
UserAudit 14919 119808 KB 119352 KB 400 KB 56 KB
Even if I use 4000 for the Detail column in my calculations I still
come up with about only 64mb.

Any ideas on whats going on here?
Thanks in advance.


Probably the first thing to try is @updateusage, and see if that changes the
figures you see:

exec sp_spaceused @updateusage = 'TRUE'

See DBCC UPDATEUSAGE for more information.

Simon
Jul 20 '05 #2
Thanks for the input Simon. I tried this and unfortunately nothing
changed.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
It seems the table is extemely fragmented.

Make sure the table has a clustered index and reindex the table.

If the table does not have a clustered index, then add a clustered index
and drop it again.

Hope this helps,
Gert-Jan
Ruaidhri Garvey wrote:

Thanks for the input Simon. I tried this and unfortunately nothing
changed.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


--
(Please reply only to the newsgroup)
Jul 20 '05 #4
Ruaidhri (rg*****@polymorphia.com) writes:
There are 14919 records in this table. When I do the calculations i
approximate that space used by this table should be in the region of
10mb (4+4+4+64+64+290(average length of Detail column)+4+256) * 14919.

When I execute "sp_spaceused 'UserAudit'" i see that 119MB are being
used by this table.

name rows reserved data index_size unused
UserAudit 14919 119808 KB 119352 KB 400 KB 56 KB
Even if I use 4000 for the Detail column in my calculations I still
come up with about only 64mb.


Gert-Jan's suggestion about fragmentation is certainly worth pursuing.
DBCC SHOWCONIG on the table can give some information. Scan Densitity
should be close to 100% for a table with low level of fragmentation.

But if we assume that many rows in fact have the maximum length, then
then value is not at all unreasonable. To wit, the maximum row size
is around 4400 bytes. And since the page size in SQL Server is 8192
bytes (with some bytes lost for internal data), you can only fit one
such row on a page. 8192*14919/1024 = 119352, which is exactly what
you have in data...

Hm, when you determined the average length of Detail, did you use the
len() function? What if you use datalength() instead? The difference
here, is that len() does not count trailing space.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #5
Great feedback Erland thanks. I think you have hit the nail on the head.

When I ran the below statement, 4000 was in fact the average. Each row
must be filled with trailing spaces.

select avg(datalength(detail))
from UserAudit

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #6
Ruaidhri Garvey (rg*****@polymorphia.com) writes:
Great feedback Erland thanks. I think you have hit the nail on the head.

When I ran the below statement, 4000 was in fact the average. Each row
must be filled with trailing spaces.

select avg(datalength(detail))
from UserAudit


There is probably reason to look into why you are save all those trailing
blanks.

Way back in 4.2 and 6.0, SQL Server always trimmed trailing spaces
when you saved data. But in ANSI SQL, the word was that trailing
spaces should be save. So in 6.5, Microsoft introduced the setting
SET ANSI_PADDING ON, and by SQL 2000, this setting is the default
in most context. While you could play with it (note that the setting
when the column was created applies), it's probably better to find out
where the spaces comes from. Maybe it is a simple that you call a
stored procedure with a parameter @detail which is char(4000).

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: wriggs | last post by:
Hi, This is probably an easy question for someone so any help would be appreciated. I have changed the columns in a table that where nvarchar to the same size of type varchar so halve the...
2
by: Oliver Stratmann | last post by:
Hello All! I've got a problem with our DB2/NT 8.1.0 Database. The following SELECT on a big Table (2,5 Million rows) finishes with the Error "Unable to allocate new pages in table space...
0
by: Fred | last post by:
Hello, I found a CLOB column in a DMS table that programmers were using to store tiny strings (less than a couple kilobytes). Since CLOB columns can only allocate entire kilobytes of space at...
5
by: N | last post by:
Hi, I got an error during load on a couple of the tables. And it seems to be complaining that I'm running out of tempspace (possibly during index rebuild). Below is the load command and error....
6
by: DH | last post by:
I have a VERY basic question about figuring database size. I've inherited a database which is generally similar to this basic one: Item, Red, Blue, Green, Yellow (text), (int),(int),(int),(int)...
0
by: Kevin Bartz | last post by:
-----Original Message----- From: Kevin Bartz Sent: Monday, August 09, 2004 10:37 AM To: 'mike@thegodshalls.com' Subject: RE: Out of swap space & memory Thanks for your reply, Mike!...
3
by: Bopolissimus Platypus Jr | last post by:
hello all, i've got a database that takes up 4G of space. when i run a script that deletes all rows and then vacuum, the data directory gets down to around 3-3.5G. what i'd like is to get a...
5
by: Konstantin Andreev | last post by:
Recently I became interested, - Are the data, bulk loaded in the table with LOAD utility, consume the same disk space as loaded with IMPORT utility? The answer turned out to be NOT ! Here is a...
10
by: Phil Stanton | last post by:
I have a table of SpaceAreas eg Food Store, Garden Shed etc with the first and last bin for each Space Area defined. eg Food Store First Space 1, last space 26 and Gargen Shed First space 1, last...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.