dbaspot
Tags Register FAQ Calendar Search Today's Posts Mark Forums Read

database table size - sqlserver-programming

This is a discussion on database table size - sqlserver-programming ; I have an MSDB database that is 256 MB in size. I ran the below script from another group to show reserved and used data by table. The sum of reserved sized is about 10 MB. THe script doesn't include ...



Reply

 

LinkBack (3) Thread Tools Display Modes
  3 links from elsewhere to this Post. Click to view. #1  
Old 06-25-2007, 05:19 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default database table size

I have an MSDB database that is 256 MB in size. I ran the below script from
another group to show reserved and used data by table. The sum of reserved
sized is about 10 MB. THe script doesn't include system tables. Is there a
way to get the sp_MSForEachTable function to include system tables?

Thanks.
DECLARE @SQL VARCHAR(255)

SET @SQL = 'DBCC UPDATEUSAGE (' + DB_NAME() + ')'

EXEC(@SQL)


CREATE TABLE #foo

(

name VARCHAR(255),

rows INT ,

reserved varchar(255),

data varchar(255),

index_size varchar(255),

unused varchar(255)

)


INSERT into #foo

EXEC sp_MSForEachtable 'sp_spaceused ''?'''


SELECT *

FROM #foo


DROP TABLE #foo


Reply With Quote
  #2  
Old 06-25-2007, 05:35 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: database table size

Most likely your size is due to the rows int he backup tables. Each time you
issue a backup there is a row written to 3 tables to record that event. By
default here is no process to delete or clean these up. You can run
sp_delete_backuphistory specifying the date that you want to remove all rows
from that point back. The first time you run it there is a good possibility
it will appear stuck but this is a very slow process with lots of data so be
patient. From then on it is quick. Create a SQL Agent job that runs this
once a week or so and you should be all set.

--
Andrew J. Kelly SQL MVP

"brian shannon" wrote in message
news:eI0Zm52tHHA.4612@TK2MSFTNGP04.phx.gbl...
>I have an MSDB database that is 256 MB in size. I ran the below script
>from another group to show reserved and used data by table. The sum of
>reserved sized is about 10 MB. THe script doesn't include system tables.
>Is there a way to get the sp_MSForEachTable function to include system
>tables?
>
> Thanks.
> DECLARE @SQL VARCHAR(255)
>
> SET @SQL = 'DBCC UPDATEUSAGE (' + DB_NAME() + ')'
>
> EXEC(@SQL)
>
>
> CREATE TABLE #foo
>
> (
>
> name VARCHAR(255),
>
> rows INT ,
>
> reserved varchar(255),
>
> data varchar(255),
>
> index_size varchar(255),
>
> unused varchar(255)
>
> )
>
>
> INSERT into #foo
>
> EXEC sp_MSForEachtable 'sp_spaceused ''?'''
>
>
> SELECT *
>
> FROM #foo
>
>
> DROP TABLE #foo
>
>



Reply With Quote
  #3  
Old 06-25-2007, 05:55 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: database table size

Thanks.

I noticed my sysdtspackages table is 605 rows but I only have about 40 DTS
packages. It appears each time I save a DTS package it appends it to the
table.

Is there a way to delete old records without deleting the current package?

Thanks.
"Andrew J. Kelly" wrote in message
news:u20OMD3tHHA.4972@TK2MSFTNGP05.phx.gbl...
> Most likely your size is due to the rows int he backup tables. Each time
> you issue a backup there is a row written to 3 tables to record that
> event. By default here is no process to delete or clean these up. You can
> run sp_delete_backuphistory specifying the date that you want to remove
> all rows from that point back. The first time you run it there is a good
> possibility it will appear stuck but this is a very slow process with lots
> of data so be patient. From then on it is quick. Create a SQL Agent job
> that runs this once a week or so and you should be all set.
>
> --
> Andrew J. Kelly SQL MVP
>
> "brian shannon" wrote in message
> news:eI0Zm52tHHA.4612@TK2MSFTNGP04.phx.gbl...
>>I have an MSDB database that is 256 MB in size. I ran the below script
>>from another group to show reserved and used data by table. The sum of
>>reserved sized is about 10 MB. THe script doesn't include system tables.
>>Is there a way to get the sp_MSForEachTable function to include system
>>tables?
>>
>> Thanks.
>> DECLARE @SQL VARCHAR(255)
>>
>> SET @SQL = 'DBCC UPDATEUSAGE (' + DB_NAME() + ')'
>>
>> EXEC(@SQL)
>>
>>
>> CREATE TABLE #foo
>>
>> (
>>
>> name VARCHAR(255),
>>
>> rows INT ,
>>
>> reserved varchar(255),
>>
>> data varchar(255),
>>
>> index_size varchar(255),
>>
>> unused varchar(255)
>>
>> )
>>
>>
>> INSERT into #foo
>>
>> EXEC sp_MSForEachtable 'sp_spaceused ''?'''
>>
>>
>> SELECT *
>>
>> FROM #foo
>>
>>
>> DROP TABLE #foo
>>
>>

>
>



Reply With Quote
  #4  
Old 06-25-2007, 06:37 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: database table size

brian shannon (brian.shannon@diamondjo.com) writes:
> I have an MSDB database that is 256 MB in size. I ran the below script
> from another group to show reserved and used data by table. The sum of
> reserved sized is about 10 MB. THe script doesn't include system
> tables. Is there a way to get the sp_MSForEachTable function to include
> system tables


You could run

SELECT object_name(id), reserved
FROM sysindexes
WHERE indid IN (0, 1)
ORDER BY reserved DESC

to see which are the biggest tables, including system tables.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Reply With Quote
  #5  
Old 06-25-2007, 07:46 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: database table size

On Jun 25, 2:18 pm, "brian shannon"
wrote:
> I have an MSDB database that is 256 MB in size. I ran the below script from
> another group to show reserved and used data by table. The sum of reserved
> sized is about 10 MB. THe script doesn't include system tables. Is there a
> way to get the sp_MSForEachTable function to include system tables?


use databasexyz;
go

SELECT CAST(OBJECT_NAME(id) AS VARCHAR(12)) AS 'Table',
CAST(rowcnt as varchar(6)) AS '#Rows',
reserved * 8 AS 'Disk - Kb',
dpages * 8 AS 'Data - Kb',
(sum(used) * 8) - (dpages * 8) AS 'Index - Kb'
FROM sysindexes
WHERE indid IN (0,1)
AND OBJECTPROPERTY(id, 'IsUserTable') = 1
GROUP BY id, rowcnt, reserved, dpages
ORDER BY 'Table';
go

See http://www.sqlhacks.com/index.php/Ad...dsForAllTables

for samples and explanations

New this week:

Which operator to use for better performance when using Microsoft SQL
Server
How to improve the union queries on Microsoft SQL Server
How many duplicates do I have in the database on an MS SQL Server
How to summarize data with Microsoft SQL Server
How to optimize Microsoft SQL Server
Web pages related to the administration of Microsoft SQL Server
How to retrieve data with Microsoft SQL Server
How to drop the time portion of a DateTime column in MS SQL Server
How to get both the details and the subtotals with Microsoft SQL
Server


Reply With Quote
  #6  
Old 06-25-2007, 08:52 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: database table size

Unfortunately I don't know how that works. You might try posting that
question in the DTS or SSIS newsgroup.


--
Andrew J. Kelly SQL MVP

"brian shannon" wrote in message
news:e493DO3tHHA.668@TK2MSFTNGP05.phx.gbl...
> Thanks.
>
> I noticed my sysdtspackages table is 605 rows but I only have about 40 DTS
> packages. It appears each time I save a DTS package it appends it to the
> table.
>
> Is there a way to delete old records without deleting the current package?
>
> Thanks.
> "Andrew J. Kelly" wrote in message
> news:u20OMD3tHHA.4972@TK2MSFTNGP05.phx.gbl...
>> Most likely your size is due to the rows int he backup tables. Each time
>> you issue a backup there is a row written to 3 tables to record that
>> event. By default here is no process to delete or clean these up. You can
>> run sp_delete_backuphistory specifying the date that you want to remove
>> all rows from that point back. The first time you run it there is a good
>> possibility it will appear stuck but this is a very slow process with
>> lots of data so be patient. From then on it is quick. Create a SQL Agent
>> job that runs this once a week or so and you should be all set.
>>
>> --
>> Andrew J. Kelly SQL MVP
>>
>> "brian shannon" wrote in message
>> news:eI0Zm52tHHA.4612@TK2MSFTNGP04.phx.gbl...
>>>I have an MSDB database that is 256 MB in size. I ran the below script
>>>from another group to show reserved and used data by table. The sum of
>>>reserved sized is about 10 MB. THe script doesn't include system tables.
>>>Is there a way to get the sp_MSForEachTable function to include system
>>>tables?
>>>
>>> Thanks.
>>> DECLARE @SQL VARCHAR(255)
>>>
>>> SET @SQL = 'DBCC UPDATEUSAGE (' + DB_NAME() + ')'
>>>
>>> EXEC(@SQL)
>>>
>>>
>>> CREATE TABLE #foo
>>>
>>> (
>>>
>>> name VARCHAR(255),
>>>
>>> rows INT ,
>>>
>>> reserved varchar(255),
>>>
>>> data varchar(255),
>>>
>>> index_size varchar(255),
>>>
>>> unused varchar(255)
>>>
>>> )
>>>
>>>
>>> INSERT into #foo
>>>
>>> EXEC sp_MSForEachtable 'sp_spaceused ''?'''
>>>
>>>
>>> SELECT *
>>>
>>> FROM #foo
>>>
>>>
>>> DROP TABLE #foo
>>>
>>>

>>
>>

>
>



Reply With Quote
Reply

Thread Tools
Display Modes


LinkBacks (?)

LinkBack to this Thread: http://dbaspot.com/forums/sqlserver-programming/188852-database-table-size.html

Posted By For Type Date
Get Size of tables in MS SQL Part 2 » Dervish Moose Blog This thread Refback 04-28-2009 05:06 PM
Dervish Moose Blog This thread Refback 01-05-2009 10:57 AM
Dervish Moose Blog: Get Size of tables in MS SQL Part 2 This thread Refback 12-23-2008 03:23 PM


All times are GMT -4. The time now is 03:29 AM.