|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Today @ 5:09 AM
Points: 415,
Visits: 1,458
|
|
To delete rows in a heap and deallocate pages, use one of the following methods.
Specify the TABLOCK hint in the DELETE statement. Using the TABLOCK hint causes the delete operation to take a shared lock on the table instead of a row or page lock. This allows the pages to be deallocated. For more information about the TABLOCK hint, see Table Hint (Transact-SQL). Use TRUNCATE TABLE if all rows are to be deleted from the table. Create a clustered index on the heap before deleting the rows. You can drop the clustered index after the rows are deleted. This method is more time consuming than the previous methods and uses more temporary resources.
How can we prove this?
I have tried checking threw DBCC command, but it is showing the space is allocated.
Can anyone prove for me please.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Tuesday, March 26, 2013 8:41 AM
Points: 2,562,
Visits: 3,451
|
|
SQL* (1/27/2013) [b]How can we prove this?
I have tried checking threw DBCC command, but it is showing the space is allocated.
Can anyone prove for me please. What has to be proved ?
-------Bhuvnesh---------- While 1 = 1 (Learning SQL....) Click to get fast response of your post
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 5:48 AM
Points: 1,076,
Visits: 1,922
|
|
SQL* (1/27/2013) To delete rows in a heap and deallocate pages, use one of the following methods.
Specify the TABLOCK hint in the DELETE statement. Using the TABLOCK hint causes the delete operation to take a shared lock on the table instead of a row or page lock. This allows the pages to be deallocated. For more information about the TABLOCK hint, see Table Hint (Transact-SQL). Use TRUNCATE TABLE if all rows are to be deleted from the table. Create a clustered index on the heap before deleting the rows. You can drop the clustered index after the rows are deleted. This method is more time consuming than the previous methods and uses more temporary resources.
How can we prove this?
I have tried checking threw DBCC command, but it is showing the space is allocated.
Can anyone prove for me please.
Could you please make it more clear? What is the problem here anyway?
- Divine Flame
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Today @ 5:09 AM
Points: 415,
Visits: 1,458
|
|
Divine Flame (1/28/2013)
SQL* (1/27/2013) To delete rows in a heap and deallocate pages, use one of the following methods.
Specify the TABLOCK hint in the DELETE statement. Using the TABLOCK hint causes the delete operation to take a shared lock on the table instead of a row or page lock. This allows the pages to be deallocated. For more information about the TABLOCK hint, see Table Hint (Transact-SQL). Use TRUNCATE TABLE if all rows are to be deleted from the table. Create a clustered index on the heap before deleting the rows. You can drop the clustered index after the rows are deleted. This method is more time consuming than the previous methods and uses more temporary resources.
How can we prove this?
I have tried checking threw DBCC command, but it is showing the space is allocated.
Can anyone prove for me please.Could you please make it more clear? What is the problem here anyway?
From the above statement from MSDN, if we use TABLOCK in the DELETE statement then the allocated pages will be deallocated.
I have checked whether there is any available space/allocated for the table, by using sp_Spaceused it is showing the allocated pages as it is. So the above statement is not true, right? But it is from MSDN so we can't tell this is wrong statement.
For the TRUNCATE TABLE statement, it is deallocating the pages.
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 7:51 AM
Points: 37,738,
Visits: 30,010
|
|
SQL* (1/28/2013) From the above statement from MSDN, if we use TABLOCK in the DELETE statement then the allocated pages will be deallocated.
If the table is a heap.
So the above statement is not true, right?
It's true.
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 5:48 AM
Points: 1,076,
Visits: 1,922
|
|
SQL* (1/28/2013)
From the above statement from MSDN, if we use TABLOCK in the DELETE statement then the allocated pages will be deallocated.
I have checked whether there is any available space/allocated for the table, by using sp_Spaceused it is showing the allocated pages as it is. So the above statement is not true, right? But it is from MSDN so we can't tell this is wrong statement.
For the TRUNCATE TABLE statement, it is deallocating the pages.
If the table is heap ( i.e. it does not have clustered index) & you use TABLOCK when deleting, the pages will be deallocated. It can be shown using undocumented command DBCC IND:
USE AdventureWorks GO IF OBJECT_ID('TheTable') IS NOT NULL BEGIN DROP TABLE TheTable; END GO CREATE TABLE TheTable ( ID INT IDENTITY(1,1), Data VARCHAR(2000) ) GO INSERT INTO TheTable (Data) VALUES (REPLICATE('SomeData',150)) GO 1000 GO --Check the number of pages allocated to the table GO DBCC IND ('AdventureWorks','TheTable',-1) -- 175 pages GO DELETE FROM TheTable WITH (TABLOCK) GO DBCC IND ('AdventureWorks','TheTable',-1) -- Only 1 page (IAM page) available & all other pages deallocated --after deleting with TABLOCK
In the above example if you delete the data without using TABLOCK the pages will not be deallocated (that also can be checked using the same DBCC IND).
- Divine Flame
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Today @ 5:09 AM
Points: 415,
Visits: 1,458
|
|
Thank you.
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Today @ 2:27 AM
Points: 350,
Visits: 1,340
|
|
|
|
|