SQL Server will reuse space made available when rows are deleted from a table. This occurs automatically without any outside intervention on our part.
However under certain circumstances, SQL Server does not automatically reclaim space once used. If a table definition is altered to drop one or more variable length columns, the space consumed by those columns is not immediately made available for reuse by SQL Server. But that's to say that the space is forever lost.
To illustrate this behavior and the aforementioned DBCC utility, let's consider an example. Let's create a table with three columns and populate it with some test data as shown in the following code.
--create a test table
CREATE TABLE dbo.Test
(
col1 INT,
col2 VARCHAR(50),
col3 VARCHAR(MAX)
) ;
--Inserting Data
INSERT INTO dbo.Test (col1, col2, col3)
VALUES (1, 'AA', 'AAAA'),
(1, 'BB', 'BBBB'),
(1, 'CC', 'CCCC'),
(1, 'DD', 'DDDD'),
(1, 'EE', 'EEEE')……….. Needs Lot of Data to Entered
Now let's view the table to make sure we have what we think we have.
SELECT *
FROM dbo.Test
Using a Dynamic Management View, let's see how much space our newly created table is consuming.
SELECT alloc_unit_type_desc,
page_count,
avg_page_space_used_in_percent,
record_count
FROM sys.dm_db_index_physical_stats(DB_ID(),
OBJECT_ID(N'dbo.Test'),
NULL,
NULL,
'Detailed') ;
alloc_unit_type_desc : IN_ROW_DATA
page_count :84
avg_page_space_used_in_percent : 78.51964418087472
record_count : 5000
Now let's drop the third column, the one that consumes the most space, and check the space used once again.
ALTER TABLE dbo.Test
DROP COLUMN col3 ;
We get the same results - 84 data pages, storing 1000 rows, each 78.6% full - even after dropping the column that consumed the most space.
Now, let's reclaim the space using the DBCC CLEANTABLE command and recheck the space consumed.
Syntax:
DBCC CLEANTABLE
( { 'database' | database_id | 0 }
, { 'table' | table_id | 'view' | view_id }
[ , batch_size]
) [WITH NO_INFOMSGS]
batch_size - The no. of rows to process per transaction.
default (or if 0 is specified) = whole table
If 0 is specified, the current database will be used.
DBCC CLEANTABLE('tempdb', 'dbo.Test')
This time, considerable less space is consumed; the average page is only filled 4.5% full!
Posted By : MR. JOYDEEP DAS
Thanks for the post.
ReplyDeleteIt is helpfull to built in depth knowledge in RDBMS.
I am expecting more and more topics from you.
https://bayanlarsitesi.com/
ReplyDeleteEskişehir
Erzincan
Ardahan
Erzurum
1HC
Yalova
ReplyDeleteHatay
Muş
Bursa
Mersin
BV8RZ8
Van
ReplyDeleteizmir
Artvin
Tunceli
Eskişehir
UBBSH
bitlis
ReplyDeletekastamonu
çorum
van
sakarya
8VK
whatsapp görüntülü show
ReplyDeleteücretli.show
ZU1BQP
whatsapp görüntülü show
ReplyDeleteücretli.show
QOY
görüntülü.show
ReplyDeletewhatsapp ücretli show
PSCL
kırklareli evden eve nakliyat
ReplyDeleteısparta evden eve nakliyat
istanbul evden eve nakliyat
ankara evden eve nakliyat
kırıkkale evden eve nakliyat
SUPMX
6DF9D
ReplyDeleteErzurum Evden Eve Nakliyat
Artvin Evden Eve Nakliyat
Sinop Evden Eve Nakliyat
Eryaman Alkollü Mekanlar
Paribu Güvenilir mi
9C048
ReplyDeleteTokat Parça Eşya Taşıma
Manisa Evden Eve Nakliyat
Aydın Parça Eşya Taşıma
Tekirdağ Parça Eşya Taşıma
Rize Parça Eşya Taşıma
Siirt Şehirler Arası Nakliyat
Sivas Lojistik
Çerkezköy Oto Boya
Ünye Halı Yıkama
E41DE
ReplyDeleteyabancı sohbet
izmir parasız sohbet siteleri
balıkesir canlı sohbet odası
muş sohbet siteleri
hakkari kadınlarla ücretsiz sohbet
afyon chat sohbet
mobil sohbet bedava
sohbet sitesi
rastgele görüntülü sohbet ücretsiz
E9FE8
ReplyDeleterastgele sohbet odaları
Burdur Canlı Sohbet Odası
görüntülü canlı sohbet
canli goruntulu sohbet siteleri
van bedava sohbet odaları
ısparta Görüntülü Sohbet Uygulamaları Ücretsiz
erzurum rastgele sohbet
Adıyaman Mobil Sohbet Odaları
eskişehir rastgele sohbet odaları
85F22
ReplyDeletedenizli seslı sohbet sıtelerı
kayseri telefonda kadınlarla sohbet
bolu mobil sohbet sitesi
Kırıkkale En İyi Görüntülü Sohbet Uygulaması
görüntülü sohbet uygulama
yozgat telefonda görüntülü sohbet
Düzce Random Görüntülü Sohbet
Ankara Görüntülü Sohbet Ücretsiz
canlı sohbet
D535A
ReplyDeleteBitcoin Nasıl Oynanır
Qlc Coin Hangi Borsada
Binance Referans Kodu
Mith Coin Hangi Borsada
Raca Coin Hangi Borsada
Gate io Borsası Güvenilir mi
Okex Borsası Güvenilir mi
Telegram Abone Satın Al
Soundcloud Dinlenme Satın Al
5HJBEDRFGCDSF
ReplyDeleteتسليك مجاري بالقطيف
شركة تنظيف سجاد بخميس مشيط Bji5dPd58Y
ReplyDeleteشركة صيانة افران بجدة 8un7NQSi3g
ReplyDeleteشركة تنظيف خزانات aivrVZ1wnH
ReplyDeleteرقم مصلحة المجاري بالاحساء H7adNRDgww
ReplyDeleteشركة مكافحة الحمام بالاحساء rYe7zTmtNA
ReplyDelete2098E872B1
ReplyDeletetwitter türk beğeni satın al
شركة عزل اسطح بالجبيل aEy5t8mll7
ReplyDeleteشركة تنظيف مجالس بالاحساء xhMnXbsMCg
ReplyDelete