我有一个定期运行的方法来优化我的应用程序的SQL Server Compact Edition (3.5)数据库。现有代码使用Shrink()方法:
SqlCeEngine engine = new SqlCeEngine(dbConnectionString);
engine.Shrink();今天我注意到还有一个Compact()方法。对于定期维护,哪种方式更可取?
发布于 2009-04-01 22:47:14
从SQL Server Compact Team Blog
这两者之间的区别与内部和外部内存碎片非常相似。从SqlCeEngine.Shrink文档中,
通过将空页和未分配页移动到文件末尾,然后截断文件,回收数据库中浪费的空间。通过在连接字符串中设置自动收缩阈值选项,可以将数据库配置为自动收缩。收缩不会创建临时数据库文件。
从SqlCeEngine.Compact文档中,
通过从现有文件创建新的数据库文件来回收数据库中浪费的空间。通过创建一个新的数据库,它回收了行之间的空闲空间。
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.https://stackoverflow.com/questions/707625
复制相似问题