共用方式為


JobSchedules Collection

未來的 Microsoft SQL Server 版本將移除這項功能。請避免在新的開發工作中使用這項功能,並規劃修改目前使用這項功能的應用程式。

The JobSchedules collection contains JobSchedule objects, each referencing one execution schedule for a SQL Server Agent job.

顯示目前物件的 SQL-DMO 物件模型

Properties

備註

A SQL Server Agent job defines an administrative task. A job may or may not be scheduled. When scheduled, SQL Server Agent evaluates the schedule or schedules associated with the job and attempts automated execution of the job at the time(s) defined by the schedule(s). When not scheduled, a job may be executed on demand by a properly authorized user.

When a SQL Server Agent job is scheduled, the JobSchedules collection of the Job object that references the job contains one or more JobSchedule objects. Use the Count property to determine the number of schedules established for the job. When the Count property of a JobSchedules collection returns 0, the job has no automated execution schedule. Use the Start method of the Job object to execute the referenced job.

With the JobSchedules collection, you can:

  • Define an execution schedule for a SQL Server Agent job.

  • Stop automated execution of a SQL Server Agent job by removing an execution schedule.

For more information about scheduling job execution by adding a JobSchedule to the JobSchedules collection, see the JobSchedule Object section.

To stop automated execution of a SQL Server Agent job

  • Use the Remove method of the JobSchedules collection, as in:

    oJob.JobSchedules.Remove("Northwind_Hourly_Log_Backup")
    

When using the Item or Remove method, the JobSchedules collection supports member identification using either name or ordinal reference syntax. For example:

Set oJobSchedule = oJob.JobSchedules("Northwind_Backup_DB")

Or

Set oJobSchedule = oJob.JobSchedules(1)

[!附註]

Scheduling automated execution of SQL Server Agent jobs using the JobSchedules collection requires appropriate privilege. The Microsoft® SQL Server™ login used for SQLServer object connection must be a member of the fixed role public in the system database msdb. With public membership, the connection may schedule jobs belonging to the connected login. Members of the db_owner role in msdb, or members of a role with greater privilege, can schedule any SQL Server Agent job.