删除行后的数据库大小不会更改

时间:2021-12-01 00:02:54

I have 2 databases from which I have deleted rows in a specific table in order to decrease the size of the database.

我有2个数据库,我从中删除了特定表中的行,以减少数据库的大小。

After deleting, the size of DB.mdf does not change.

删除后,DB.mdf的大小不会更改。

I also tried to rebuild the index and used cleantable, but to no effect!

我也尝试重建索引并使用清晰,但没有效果!

ALTER INDEX ALL ON dbo.'Tablename' REBUILD

DBCC CLEANTABLE ('DBname', 'Tablename', 0)

1 个解决方案

#1


1  

Deleting rows in a database will not decrease the actual database file size.

删除数据库中的行不会减少实际的数据库文件大小。

You need to compact the database after row deletion.

删除行后需要压缩数据库。

Look for this After running this, you'll want to rebuild indexes. Shrinking typically causes index fragmentation, and that could be a significant performance cost.

寻找这个在运行之后,您将需要重建索引。缩小通常会导致索引碎片化,这可能会带来显着的性能损失。

I would also recommend that after you shrink, you re-grow the files so that you have some free space. That way, when new rows come in, they don't trigger autogrowth. Autogrowth has a performance cost and is something you would like to avoid whenever possible.

我还建议您在缩小之后重新生成文件,以便有一些可用空间。这样,当新行进入时,它们不会触发自动增长。 Autogrowth具有性能成本,您可以尽可能避免这种情况。

#1


1  

Deleting rows in a database will not decrease the actual database file size.

删除数据库中的行不会减少实际的数据库文件大小。

You need to compact the database after row deletion.

删除行后需要压缩数据库。

Look for this After running this, you'll want to rebuild indexes. Shrinking typically causes index fragmentation, and that could be a significant performance cost.

寻找这个在运行之后,您将需要重建索引。缩小通常会导致索引碎片化,这可能会带来显着的性能损失。

I would also recommend that after you shrink, you re-grow the files so that you have some free space. That way, when new rows come in, they don't trigger autogrowth. Autogrowth has a performance cost and is something you would like to avoid whenever possible.

我还建议您在缩小之后重新生成文件,以便有一些可用空间。这样,当新行进入时,它们不会触发自动增长。 Autogrowth具有性能成本,您可以尽可能避免这种情况。