Question : sp_spaceused

I noticed our data size grew 3 gigs last night when i di
exec Sp_SpaceUsed
i noticed negative numbers so i did
dbcc updateusage ('testcp') WITH COUNT_ROWS
and it was ok....fixed the values.

So should i do a dts job each night to do this
exec sp_spaceused @updateusage = 'TRUE'
dbcc updateusage ('testcp') WITH COUNT_ROWS

for all my tables.....

does any one else run these overnight.
Cheers.

Answer : sp_spaceused

Next batch will do all databases on a server. But it does not write the output to a table.

DECLARE @DB_name VARCHAR(50)
DECLARE @Readonly INT
DECLARE @cmd VARCHAR(255)
SET NOCOUNT ON
CREATE TABLE #DB([name] nvarchar(24), [db_size] nvarchar(13), [owner] nvarchar(24), [dbid] smallint, [created] char(11), [status] varchar(340), [compatibility_level] tinyint)

INSERT INTO #DB
EXEC sp_helpdb

DECLARE DB_Cursor CURSOR
FOR SELECT t.[Name]
         , CASE WHEN sd.status & power(2, 10) = 0 THEN 0 ELSE 1 END AS [Readonly]
    FROM master..sysdatabases sd
       , #DB t
    WHERE t.dbid = sd.dbid
    ORDER BY [db_size] asc

OPEN DB_Cursor
FETCH NEXT FROM DB_Cursor INTO @DB_name, @Readonly
WHILE(@@FETCH_STATUS <> -1)
BEGIN
  print @DB_name
  IF (@Readonly = 0)
  BEGIN
    SELECT @cmd = 'DBCC UPDATEUSAGE([' + @DB_name + ']) WITH NO_INFOMSGS'
    EXEC (@cmd)
  END
  FETCH NEXT FROM DB_Cursor INTO @DB_Name, @Readonly
END
CLOSE DB_Cursor
DEALLOCATE DB_Cursor
SET NOCOUNT OFF
DROP TABLE #DB
Random Solutions  
 
programming4us programming4us