SQL作业:如何开始?

发布于 2024-08-18 22:13:43 字数 125 浏览 4 评论 0原文

任何人都可以帮助我在 SQL Server 代理(SQL 2008)中创建一个 SQL 作业,该作业将在特定的时间间隔(例如:每日)运行,并从状态 = 1 的表中选择记录(选择学生的姓名、年龄)和传递到另一个接受学生姓名和年龄的存储过程

Can anyone help me to create an SQL job in SQL server Agent (SQL 2008) ,which will run in a purticular time interval(Ex: Daily) and select records from a table with status=1 (select name,age from student)and pass to another stored procedure which accepts student name and age

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

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

发布评论

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

评论(1

美煞众生 2024-08-25 22:13:43

这是我将采取的方法:

创建脚本

  • 创建一个包含游标的 SQL 脚本(我说游标的唯一原因是因为您将学生姓名和年龄传递给不同的存储过程)
  • 读取将 StudentName 和 Age 放入 @variables
  • 使用适当的参数执行存储过程
  • 获取下一行并循环
  • IMP:测试脚本

将脚本保存在 SQL 文件中以供进一步参考。

在 SQL Server 代理中

  • 创建一个新作业,
  • 将其指向适当的数据库
  • 将 SQL 脚本(从上面)粘贴到作业的脚本区域中
  • 创建适当的计划(每天,凌晨 3:15)
  • 如果操作员和 SQL Mail 已设置,添加它们以便您可以收到电子邮件通知
  • 保存作业
  • IMP:测试作业

Here is the approach I would take:

Create the script

  • Create a SQL script with a CURSOR in it (the only reason I say cursor is because you are passing Student Name and Age to a different stored procedure)
  • Read the StudentName and Age into @variables
  • Execute the stored proc with appropriate parameters
  • Fetch next row and loop
  • IMP: TEST the script

Save the script in a SQL file for further reference.

In SQL Server Agent

  • Create a new job
  • point it to the appropriate database
  • Paste the SQL Script (from above) into the script area of the job
  • Create an appropriate schedule (daily, at 3:15 am)
  • If operators and SQL Mail are setup, add those so that you can get email notifications
  • Save the job
  • IMP: TEST the job
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文