sp_spaceused returns same even after deleteing 3.5 lac records.

  • Dear All,

    In one of my table there are only 2 fields.

    1 autoincrement column

    2 varchar column.

    previously there were only 3 records.

    I executed 'sp_spaceused 'tablename'' and I got the following values

    Reserved -16kb

    Data -8kb

    Then I INSERTED 3.5 lac records and I got.

    Reserved -10568 KB

    Data -10528 KB

    After that I DELETED all the records except the first 3. But still am getting the space used details as follows.

    Reserved -10568 KB

    Data -10528 KB

    Why so.? Won't it decrease if we DELETE records..?

    Thanks.

  • Does this table have a clustered index? If not, you might see this behavior. I am not 100% sure but I have seen this happen in SQL 2000 but I have never come across this situation in SQL 2005 DB.

    -Roy

  • Taken straight from Books Online:

    When updateusage is specified, the SQL Server 2005 Database Engine scans the data pages in the database and makes any required corrections to the sys.allocation_units and sys.partitions catalog views regarding the storage space used by each table. There are some situations, for example, after an index is dropped, when the space information for the table may not be current. updateusage can take some time to run on large tables or databases. Use updateusage only when you suspect incorrect values are being returned and when the process will not have an adverse effect on other users or processes in the database. If preferred, DBCC UPDATEUSAGE can be run separately.

    Note:

    When you drop or rebuild large indexes, or drop or truncate large tables, the Database Engine defers the actual page deallocations, and their associated locks, until after the transaction commits. Deferred drop operations do not release allocated space immediately. Therefore, the values returned by sp_spaceused immediately after dropping or truncating a large object may not reflect the actual disk space available. For more information about deferred allocations, see Dropping and Rebuilding Large Objects

    --Ramesh


Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply