简体   繁体   English

SQL Server:数据库维护计划

[英]SQL Server: Database Maintenance Plan

I have a small database for a school project and I need to create a Database Maintenance Plan with the following requirements: 我有一个用于学校项目的小型数据库,我需要创建具有以下要求的数据库维护计划:

  • it has to manually (through scripting and not user interface) 它必须手动(通过脚本而不是用户界面)
  • it must reorganize data and indexes 它必须重组数据和索引
  • it must validate database integrity 它必须验证数据库完整性
  • it must be run automatically everyday at 19:00 它必须每天19:00自动运行

well, I have absolutely no idea on how to do this 好吧,我绝对不知道该怎么做

Can someone help me out, please? 有人可以帮我吗?

I found some commands to create backups and reorganize indexes but I can't find a way to run them periodically. 我找到了一些用于创建备份和重组索引的命令,但是我找不到定期运行它们的方法。

Thanks Chiapa 谢谢恰帕

If you want to create a maintenance plan, see the follwing page: 如果要创建维护计划,请参见以下页面:

Use the Maintenance Plan Wizard 使用维护计划向导

Otherwise, you can just create a SQL agent job with various steps in it that run the T-SQL commands that you want, such as backup database and DBCC commands and create a schedule for it. 否则,您可以只创建一个SQL代理作业,其中包含执行所需的T-SQL命令(例如备份数据库和DBCC命令)的各种步骤,并为其创建日程表。

If you cannot use the maintenance plan wizard, you can use commands similar to those detailed in the following page to create the jobs: 如果无法使用维护计划向导,则可以使用与下一页中详述的命令类似的命令来创建作业:

Create a Maintenance Plan 创建维护计划

If you can't create agent jobs (for reasons such as you are using a version of SQL server that doesn't support them (SQL Express etc) then you can use OSQL commands that are fired by Windows task scheduler to achieve much the same thing, see the folowing link for a very good description: 如果您无法创建代理作业(由于某种原因(例如,您正在使用不支持代理服务器的SQL Server版本)(SQL Express等)),则可以使用Windows任务计划程序触发的OSQL命令来达到相同的目的事情,请参阅下面的链接以获取非常好的描述:

How to Automate Maintenace Tasks with SQL Server Express 如何使用SQL Server Express自动执行维护任务

如果您有可用的命令,并且使用的是具有SQL代理的SQL Server版本,请创建一个代理作业,然后使用该作业进行调度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM