• Maintenance Plans in MS SQL 2005


    Maintenance Plans in MS SQL 2005 are a powerful and easy way to manage and backup your databases. In this article, I’m going to walk through 4 basic tasks that we run weekly on a client’s database. You’ll learn how to reorganize indexes, create a full backup (*.bak), shrink your database (shrinks both data and log files), and cleanup the backup directory.

    Creating a Maintenance Plan

    In SQL Server Management Studio, expand the Management folder, right-click Maintenance Plans and select New Maintenance Plan…


    Give the Maintenance Plan a name and click OK. The new empty Maintenance Plan will open in Design Mode. All of the available tasks are in the left hand column Toolbox under Maintenance Plan Tasks.


    To add any task to the maintenance plan, simply drag the task from the Toolbox into the design frame. Once the task is in the design frame, double-click to edit.

    Reorganize Index Task

    The reorganize index task updates table and view indexes so the search order is more efficient. The task dialogue is pretty simple. Use the Database(s) drop down to select one or more databases. Then use the Object drop down to select whether Tables, Views, or Both should have their indexes reorganized. For this example, I’m going to reorganize both Tables and Views. When done, click OK.


    Back Up Database Task

    The Back Up Database Task creates a Full, Differential, or Transaction Log backup. In this example, I’m going to create a Full backup which will create a *.bak file.  This task dialogue is also pretty simple. Set the Backup type to Full and then select the Database(s) to backup. Jump down to the bottom third of the

    Join the Reorganize Index Task to the Backup Database Task by dragging the green arrow between the two. Once the two tasks are joined, right-click the arrow and select Completion.


    Shrink Database Task

    The Shrink Database Task should come after the back up task because the shrink cannot be executed on a database until a Full backup has been created. In the task dialogue, select the Database(s) and just accept the defaults. When done, click OK. If you’ve noticed your log files getting out of hand, the shrink task will bring the file size down. In a recent test, my active log file went from over 2GB to just over 200MB.


    Join the Back Up Database Task to the Shrink Database Task, and set the type to Completion.

    Maintenance Cleanup Task

    As the last task in the Maintenance Plan, I’m going to cleanup the backup directory by removing any *.bak files that are older than 2 weeks. If you’re doing this type of maintenance, you’ll want to make sure you’ve got some sort of server backup that keeps a longer history of your *.bak files off-server.

    Open the task dialogue and skip down to the Search folder and delete files based on extension.  Navigate to the backup folder that was set in the Back Up Database Task. Then set the file extension to bak. Note the extension is simply bak. You don’t need to include a . (dot). Skip to the bottom of the dialogue and set the age of the deleted files to 2 weeks. When done, click OK.


    Join the Shrink Database Task to the Maintenance Cleanup Task, and set the type to Success.

    Execute the Maintenance Plan

    Save the maintenance plan. From the Object Explorer, right click the new plan and select Execute to test it.  If everything runs without error, you can set the plan to run on a schedule.

    On the design mode screen in the Subplan grid, click on the calendar icon and set the schedule for executing the plan. When done, click OK.

    That’s it. The plan will now run as a scheduled task. Not only does the plan backup the database, but it’s also reorganizing the indexes, shrinking the database and cleaning up  the backup directory. Best of all, once it’s setup, the plan executes without your intervention and at a time that is best for your system.

    reference:  http://www.webapper.com/blog/index.php/2009/09/10/ms-sql-maintenance-plans/

  • 相关阅读:
    2015年6月8-9日,杨学明老师《研发多项目管理》专题培训在北京某企业成功举办!
    2015年5月22-23日,杨学明老师《软件测试管理》专题培训在惠州成功举办!
    现代浏览器性能之争
    为libevent添加websocket支持(上)
    使用MUI/html5plus集成微信支付需要注意的几点问题
    在Win32程序中嵌入Edge浏览器组件
    纯中文C++代码,可运行
    修改minifest使桌面软件支持高dpi
    手机操作系统功能对照表
    HTML+JS+JQuery不可以使用status
  • 原文地址:https://www.cnblogs.com/sandy_liao/p/1849258.html
Copyright © 2020-2023  润新知