Microsoft SQL Server 2008 LDF数据文件清理方法。
PS:由于该操作涉及数据库中的数据,请在操作前先做好数据备份。
准备:Microsoft SQL Server 2008清理LDF脚本,请点击下载获取。下载完毕后,请放置C盘根目录并解压。
1、开始-所有程序-找到Microsoft SQL Server 2008 R2-SQL Server Management Studio(如图1-1)
![img_690dde0204a5421c14ca73152ed58b95.png](https://yqfile.alicdn.com/img_690dde0204a5421c14ca73152ed58b95.png?x-oss-process=image/resize,w_1400/format,webp)
图 1-1
2、在【连接到服务器】窗口,点击【连接】(如图1-2)。
![img_fc69f43614554015d9ae5940b0d8ee2a.png](https://yqfile.alicdn.com/img_fc69f43614554015d9ae5940b0d8ee2a.png?x-oss-process=image/resize,w_1400/format,webp)
图 1-2
3、在【对象资源管理器】下方找到【数据库】- 找到需要清理LDF日志的数据库(如图1-3中的MY20),右键 -【新建查询】。
![img_9e6d86271fc899e4491b6d7cb68048ca.png](https://yqfile.alicdn.com/img_9e6d86271fc899e4491b6d7cb68048ca.png?x-oss-process=image/resize,w_1400/format,webp)
图 1-3
4、点击【打开文件】-【查找范围】中找到脚本存放位置,选择引导语中脚本【第二个执行(清理LDF)】-【打开】(如图1-4)。
![img_51d075f52fb48ce2a9ffd1d4b1bc7e0b.png](https://yqfile.alicdn.com/img_51d075f52fb48ce2a9ffd1d4b1bc7e0b.png?x-oss-process=image/resize,w_1400/format,webp)
图 1-4
5、把打开脚本中的【数据库名】全部修改成需要清理LDF日志的数据库名称(如图1-5-1中的MY20,修改后如图1-5-2)。
![img_7d86b970d562d531ed53a9fe3be6a366.png](https://yqfile.alicdn.com/img_7d86b970d562d531ed53a9fe3be6a366.png?x-oss-process=image/resize,w_1400/format,webp)
图 1-5-1
![img_66a10fe4f658986e6d14a29d1ba9c265.png](https://yqfile.alicdn.com/img_66a10fe4f658986e6d14a29d1ba9c265.png?x-oss-process=image/resize,w_1400/format,webp)
图 1-5-2
6、找到需要清理LDF日志的数据库(如图1-6中的MY20),右键【属性】。
![img_f0d59cc8793c06ddf4c0d3315c062ec9.png](https://yqfile.alicdn.com/img_f0d59cc8793c06ddf4c0d3315c062ec9.png?x-oss-process=image/resize,w_1400/format,webp)
图 1-6
7、在【数据库属性】窗口,点击【文件】- 找到日志名称,点击鼠标右键-复制-【取消】。
![img_4f0d578c1071e0a1587020da231cd7ac.png](https://yqfile.alicdn.com/img_4f0d578c1071e0a1587020da231cd7ac.png?x-oss-process=image/resize,w_1400/format,webp)
图 1-7
8、在回到脚本窗口,把【日志文件名】全选(如图1-8-1),然后点击鼠标右键粘贴(如图1-8-2)。
![img_f7a52e956ea0095a638b508254f975af.png](https://yqfile.alicdn.com/img_f7a52e956ea0095a638b508254f975af.png?x-oss-process=image/resize,w_1400/format,webp)
图 1-8-1
![img_e1dab77b192f6fa54a7a0dabd0a4876e.png](https://yqfile.alicdn.com/img_e1dab77b192f6fa54a7a0dabd0a4876e.png?x-oss-process=image/resize,w_1400/format,webp)
图 1-8-2
9、点击【执行】后,等待下方显示【查询已成功执行】即执行完成(如图1-9)。
![img_3ffde1699d2b73d7f364150f1de3c7fe.png](https://yqfile.alicdn.com/img_3ffde1699d2b73d7f364150f1de3c7fe.png?x-oss-process=image/resize,w_1400/format,webp)
图 1-9