Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Space that a table uses is not completely released after you use a DELETE statement to delete data from the table in SQL Server


Bug #: 219514 (SQL Server 8.0)

↑ Back to the top


Symptoms

After you use a DELETE statement in Microsoft SQL Server to delete data from a table, you may notice that the space that the table uses is not completely released. When you then try to insert data in the database, you may receive the following error message:
Could not allocate space for object 'TableName' in database 'DatabaseName' because the 'PRIMARY' filegroup is full.
Note TableName represents the name of the table. DatabaseName represents the name of the database that contains the table.

↑ Back to the top


Cause

This problem occurs because SQL Server only releases all the pages that a heap table uses when the following conditions are true:
  • A deletion on this table occurs.
  • A table-level lock is being held.
Note A heap table is any table that is not associated with a clustered index.

If pages are not deallocated, other objects in the database cannot reuse the pages.

However, when you enable a row versioning-based isolation level in a SQL Server 2005 database, pages cannot be released even if a table-level lock is being held. For more information about row versioning-based isolation levels, see the "Using Row Versioning-based Isolation Levels" topic in SQL Server 2005 Books Online.

↑ Back to the top


Workaround

To work around this problem, use one of the following methods:

  • Include a TABLOCK hint in the DELETE statement if a row versioning-based isolation level is not enabled. For example, use a statement that is similar to the following:
    DELETE FROM <TableName> WITH (TABLOCK)
    Note <TableName> represents the name of the table.
  • Use the TRUNCATE TABLE statement if you want to delete all the records in the table. For example, use a statement that is similar to the following:
    TRUNCATE TABLE <TableName>
  • Create a clustered index on a column of the table. For more information about how to create a clustered index on a table, see the "Creating a Clustered Index" topic in SQL Server Books Online.

↑ Back to the top


Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

↑ Back to the top


Keywords: kb, kbprb, kbexpertiseadvanced

↑ Back to the top

Article Info
Article ID : 913399
Revision : 5
Created on : 8/19/2020
Published on : 8/20/2020
Exists online : False
Views : 74