SQL Server:我应该使用“代理作业”吗?或“维护计划”删除旧数据?

发布于 2024-08-06 22:18:01 字数 202 浏览 6 评论 0原文

我正在寻找一种方法来定期(例如每周)在数据库中运行一些 SQL 语句来删除旧数据。据我所知,(至少)有两种方法可以做到这一点:

  • 使用“维护计划”和“执行 T-SQL 语句任务”,
  • 使用“SQL Server 代理作业”并在“该工作的“步骤”

我的问题是:这两种可能性之间有什么区别,我应该使用哪一种来完成我的任务?

I'm looking for a way to periodically (e.g. weekly) run some SQL statements in a database to delete old data. As far as I can see, there are (at least) two ways to do this:

  • using a "Maintenance Plan" and a "Execute T-SQL Statement Task"
  • using an "SQL Server Agent Job" and specify the statements in a "Step" of that job

My question is: what is the difference between these two possibilities and which one should I use for my task?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囚你心 2024-08-13 22:18:01

这并不是一个非此即彼的选择,而是一个非此即彼的选择。有一些重叠。

将维护计划视为对数据库“执行某些操作”的步骤的集合;这些步骤被封装到需要安排运行的计划中。

SQL Server代理是定期运行作业的服务;作业是计划运行的任何内容。维护计划是一项工作。

当您计划运行维护计划时,您实际上是在创建一个作业(或多个作业;感谢 DJ),以便 SQL Server 代理定期运行。

现在,至于选择哪种方式最好(通过维护计划向导或直接通过代理),我想说,对于大多数数据库来说,维护计划向导就足够了。您可能希望向维护计划创建的作业添加其他步骤,但这取决于您的环境。

这有道理吗?

It's not really an either/or choice; there's some overlap.

Think of a Maintenance Plan as a collection of steps to "do something" to your databases; those steps are encapsulated into a plan which needs to be scheduled to run.

The SQL Server Agent is the service that periodically runs jobs; a job is anything that is scheduled to run. A Maintenance Plan is a job.

When you schedule a Maintenance Plan to run, you are actually creating a job (or jobs; thanks DJ) for the SQL Server Agent to run periodically.

Now, as to choosing which way is best (to go through the Maintenance Plan wizard or directly through the Agent), I would say that for most databases, the Maintenance Plan Wizard is suffecient. You may want to add additional steps to the job(s) created by the Maintenance Plan, but that depends on your environment.

Does that make sense?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文