Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12963

17 GB of data but database is 290GB WHY????

$
0
0

I ran the below query and it came up with 17GB of data. My database is 290GB. This doesn't make sense. I know because of all the other object of course it would be bigger but not that much bigger. Does anyone have an answer? And please don't say SP's, trigger,s views etc. That doesn't make up 275 GB of data.

DECLARE @TableName VARCHAR(100)    --For storing values in the cursor
--Cursor to get the name of all user tables from the sysobjects listing
DECLARE tableCursor CURSOR FOR  
select [name] from dbo.sysobjects  where  OBJECTPROPERTY(id, N'IsUserTable') = 1 FOR READ ONLY
--A procedure level temp table to store the results
CREATE TABLE #TempTable (     tableName varchar(100),     numberofRows varchar(100),     reservedSize varchar(50),     dataSize varchar(50),     indexSize varchar(50),     unusedSize varchar(50) )
--Open the cursor
OPEN tableCursor
--Get the first table name from the cursor
FETCH NEXT FROM tableCursor INTO @TableName
--Loop until the cursor was not able to fetch
WHILE (@@Fetch_Status >= 0) BEGIN     
--Dump the results of the sp_spaceused query to the temp table     
INSERT  #TempTable         
EXEC sp_spaceused @TableName     
--Get the next table name     
FETCH NEXT FROM tableCursor INTO @TableName END
--Get rid of the cursor
CLOSE tableCursor
DEALLOCATE tableCursor
--Select all records so we can use the reults
SELECT *  FROM #TempTable
order by 2
--Final cleanup!
DROP TABLE #TempTable
GO


Alan


Viewing all articles
Browse latest Browse all 12963

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>