寻找 T-SQL 脚本来删除 SQL 作业

发布于 2024-07-29 16:48:43 字数 156 浏览 3 评论 0原文

如果我知道数据库服务器名称、实例名称和 SQL Server 作业名称,如何以简单的方式通过名称删除 SQL Server 作业? 我正在编写将由 sqlcmd 调用的脚本来删除 SQL 作业。

如果有人可以给我看样品吗? :-)

提前致谢, 乔治

If I know the database server name, instance name and the SQL Server job name, how to delete a SQL Server job by its name in a simple way? I am writing scripts which will be called by sqlcmd to delete SQL jobs.

Appreciate if anyone could show me a sample? :-)

thanks in advance,
George

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

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

发布评论

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

评论(3

江湖彼岸 2024-08-05 16:48:45
USE msdb;

GO

EXEC sp_delete_job
    @job_name = N'NightlyBackups' ;

GO
USE msdb;

GO

EXEC sp_delete_job
    @job_name = N'NightlyBackups' ;

GO
杀手六號 2024-08-05 16:48:45

您正在寻找sp_delete_job

[srv].[master].[dbo].sp_delete_job @job_name = 'MyJob'

因此,这四个部分的名称仅适用于链接服务器。 否则,您必须连接到服务器,并对其运行该命令(使用 [dbo]. 的所有内容。

You're looking for sp_delete_job:

[srv].[master].[dbo].sp_delete_job @job_name = 'MyJob'

So this four part name only works with linked servers. Otherwise, you'll have to connect to the server, and run that command against it (with everything right of [dbo]..

千里故人稀 2024-08-05 16:48:45

值得注意的是,您可以使用 SSMS,选择作业,右键单击并选择“删除”,然后使用对话框顶部的“脚本”按钮生成一个脚本,如此处建议的那样。

It's worth noting that you can just use SSMS, choose the job, right-click and pick "Delete", and then use the Script button at the top of the dialog box to generate a script like the ones suggested here.

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