.net – 在Sql Server CE中缩小或压缩?

我正在使用Visual Studio 2008.我是新的sqlce.我正在检查sdf文件,如果sdf不存在,我创建然后插入大约5000行到我的sqlce db.If sdf存在,首先我删除所有表的行然后将这些记录插入到现有的表中.插入完成后,我正在压缩数据库.顺便说一下,压缩持续大约13秒.我知道一个调用Shrink.Shrink和Compact的方法使db变小但是在这个scenerio中我应该使用哪个?如何在更短的时间内进行压缩?我不需要备份sdf和紧凑后,我删除旧的sdf.i阅读 this主题,但无法决定我应该使用.

解决方法

请参阅:

> What is the difference between Shrink and Compact in SQL Server CE?

来自SQL Server Compact Team Blog的报价:

sqlCeEngine/ISSCEEngine: Shrink Vs Compact The difference between
these two is much similar to Internal
and External Memory Fragmentation.

From 07002:

Reclaims wasted space in the database
by moving empty and unallocated pages
to the end of the file,and then
truncating the file. You can
configure a database to automatically
shrink by setting the autoshrink
threshold option in connection string.
Shrink does not create a temporary
database file.

From 07003:

Reclaims wasted space in the database
by creating a new database file from
the existing file. By creating a new
database means,it reclaims the free
space between rows.

To be more clear,Shrink claims the
pages which are entirely free or
unallocated; where as,Compact claims
the wasted space with in the page too.
Hence Compact requires creating a new
database file.

Empty space with in the page Could be
as result of:

1) If there were 5 rows in a page
and two of them are deleted

2) If there was a row in the middle of the
page which on update required more
space,has moved out of the page (Ex:
nvarchar column update)

Empty pages and unallocated pages
Could remain in database as a result
of:

1) All rows in a page are deleted

2) Whole table is dropped

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...