SQL Server CE 中的收缩和压缩有什么区别? [英] What is the difference between Shrink and Compact in SQL Server CE?

查看:35
本文介绍了SQL Server CE 中的收缩和压缩有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个定期运行的方法来优化我的应用程序的 SQL Server Compact Edition (3.5) 数据库.现有代码使用 Shrink() 方法:

I have a method that is run periodically to optimise my application's SQL Server Compact Edition (3.5) database. The existing code uses the Shrink() method:

        SqlCeEngine engine = new SqlCeEngine(dbConnectionString);
        engine.Shrink();

今天我注意到还有一个 Compact() 方法.哪个更适合定期维护?

Today I noticed that there's also a Compact() method. Which is preferable for periodic maintenance?

推荐答案

来自 SQL Server Compact 团队博客:

这两者的区别在于非常类似于内部和外部内存碎片.

The difference between these two is much similar to Internal and External Memory Fragmentation.


来自 SqlCeEngine.Shrink 文档,

回收数据库中浪费的空间通过移动空的和未分配的页面到文件末尾,然后截断文件.你可以将数据库配置为自动通过设置自动收缩来收缩连接字符串中的阈值选项.收缩不会创建临时数据库文件.

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.

来自 SqlCeEngine.Compact文档,

回收数据库中浪费的空间通过从创建一个新的数据库文件现有文件.通过创建一个新数据库意味着,它回收免费行之间的空间.

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.


更清楚地说,Shrink 声称完全免费的页面或未分配;其中,Compact 声称页面中也浪费了空间.因此 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.

这篇关于SQL Server CE 中的收缩和压缩有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆