SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Script to show space used
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

TimS
Posting Yak Master

USA
198 Posts

Posted - 05/06/2005 :  19:06:38  Show Profile  Reply with Quote
--
-- Create a script to cut & paste to new QA window and it shows space
-- used using the sp_spaceused proc.
-- Note not using indexes with status of 8 because it error out
-- reason for error unknown
-- Tim S
--

SET NOCOUNT ON;
PRINT '
create table #my_space
(
name nvarchar(128),
rows int null,
reserved nvarchar(128),
data nvarchar(128),
index_size nvarchar(128),
unused nvarchar(128)
);
';
PRINT 'SET NOCOUNT ON;';
SELECT 'INSERT INTO #my_space(name, rows, reserved, data, index_size, unused) ' +
'EXEC sp_spaceused @objname = ' +
QUOTENAME(QUOTENAME(USER_NAME(uid)) + '.' +
QUOTENAME(name), '''') -- + ', @updateusage = ''true'';'
FROM sysobjects obj
where xtype in ('S','U') AND EXISTS (
SELECT * FROM sysindexes ind
WHERE obj.id = ind.id AND ind.indid < 2 AND ind.status <> 8
);
PRINT '
select name, rows, reserved, data, index_size, unused
from #my_space
ORDER BY CAST(REPLACE(data, ''KB'', '''') AS INT) DESC;
';
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000