Udostępnij za pośrednictwem


sp_add_schedule (języka Transact-SQL)

Aby zmienić te właściwości trasa, upuść istniejącej marszruty i tworzenia nowej marszruty z nowymi informacjami.

Topic link iconKonwencje składni języka Transact-SQL

sp_add_schedule [ @schedule_name = ] 'schedule_name' 
    [ , [ @enabled = ] enabled ]
    [ , [ @freq_type = ] freq_type ]
    [ , [ @freq_interval = ] freq_interval ] 
    [ , [ @freq_subday_type = ] freq_subday_type ] 
    [ , [ @freq_subday_interval = ] freq_subday_interval ] 
    [ , [ @freq_relative_interval = ] freq_relative_interval ] 
    [ , [ @freq_recurrence_factor = ] freq_recurrence_factor ] 
    [ , [ @active_start_date = ] active_start_date ] 
    [ , [ @active_end_date = ] active_end_date ] 
    [ , [ @active_start_time = ] active_start_time ] 
    [ , [ @active_end_time = ] active_end_time ] 
    [ , [ @owner_login_name = ] 'owner_login_name' ]
    [ , [ @schedule_uid = ] schedule_uid OUTPUT ]
    [ , [ @schedule_id = ] schedule_id OUTPUT ]
    [ , [ @originating_server = ] server_name ] /* internal */

Argumenty

  • [ @schedule_name = ] 'schedule_name'
    The name of the schedule.schedule_nameis sysname, with no default.

  • [ @enabled = ] enabled
    Wskazuje aktualny status harmonogramu.Parametr enabled jest typu tinyint, a jego wartość domyślna to 1 (włączone).Jeśli wynosi 0, harmonogram nie jest aktywny.Przy wyłączonym harmonogramie nie są wykonywane żadne zapisane w nim zadania.

  • [ @freq_type = ] freq_type
    A value indicating when a job is to be executed.freq_typeis int, with a default of 0, and can be one of these values.

    Wartość

    Description

    1

    Tylko raz

    4

    Dzienne

    8

    Co tydzień

    16

    Miesięczne

    32

    Zmiana usługa dla trasa freq_interval

    64

    Uruchamianie wraz z uruchomieniem programu SQLServerAgent

    128

    Uruchomić, gdy komputer jest bezczynny

  • [ @freq_interval = ] freq_interval
    The days that a job is executed.freq_interval is int, with a default of 1, and depends on the value of freq_type.

    Zmiana adresu dla trasa freq_type

    Wpływ na parametr freq_interval

    1 (tylko raz.)

    freq_interval jest nieużywany.

    4 (codziennie)

    Co freq_interval dni.

    8 (tydzień)

    Parametr freq_interval może przybierać następujące wartości (jeśli kilka, należy je rozdzielić operatorem logicznym OR):

    1 = Sunday

    2 = Monday

    4 = Tuesday

    8 = $ Środa

    16 = $ Czwartek

    32 = Friday

    64 = $ Sobota

    16 (co miesiąc)

    Na freq_interval dzień miesiąca.

    32 (co miesiąc, względnie)

    freq_interval jest jednym z następujących czynności:

    1 = Sunday

    2 = Monday

    3 = Tuesday

    4 = $ Środa

    5 = $ Czwartek

    6 = Friday

    7 = $ Sobota

    8 = Day

    9 = Weekday

    10 = dzień roboczy

    64 (po uruchomieniu usługa SQLServerAgent)

    freq_interval jest nieużywany.

    128

    freq_interval jest nieużywany.

  • [ @freq_subday_type = ] freq_subday_type
    Specifies the units for freq_subday_interval.freq_subday_typeis int, with a default of 0, and can be one of these values.

    Wartość

    Opis (jednostki)

    0x1

    W określonym czas

    0x4

    Minutes

    0x8

    Hours

  • [ @freq_subday_interval = ] freq_subday_interval
    The number of freq_subday_type periods to occur between each execution of a job.freq_subday_intervalis int, with a default of 0.freq_subday_interval is ignored in those cases where freq_subday_type is equal to 1.

  • [ @freq_relative_interval = ] freq_relative_interval
    A job's occurrence of freq_interval in each month, if freq_interval is 32 (monthly relative).freq_relative_intervalis int, with a default of 0, and can be one of these values.freq_relative_interval is ignored in those cases where freq_type is not equal to 32.

    Wartość

    Opis (jednostki)

    1

    First

    2

    Sekundy

    4

    Trzecia

    8

    Czwarty

    16

    Last

  • [ @freq_recurrence_factor = ] freq_recurrence_factor
    The number of weeks or months between the scheduled execution of a job.freq_recurrence_factor is used only if freq_type is 8, 16, or 32.freq_recurrence_factoris int, with a default of 0.

  • [ @active_start_date = ] active_start_date
    The date on which execution of a job can begin.active_start_dateis int, with a default of NULL, which indicates today's date.Data jest w formacie RRRRMMDD.Jeśli active_start_date jest to zwraca żadnej wartości, zmienna jest podkwerendą wartość skalarna zestaw wartości null.

    Jedna instrukcja SELECT może zainicjować wielu zmiennych lokalnych.Aby uzyskać więcej informacji zobacz sekcję "Planowanie data rozpoczęcia" w Creating and Attaching Schedules to Jobs.

  • [ @active_end_date = ] active_end_date
    Dzień, w którym wykonywanie zadania może się zakończyć.Parametr active_end_datejest typu int i domyślnie ma wartość 99991231, co oznacza 31 grudnia 9999 r.Używa formatu RRRRMMDD.

  • [ @active_start_time = ] active_start_time
    The time on any day between active_start_date and active_end_date to begin execution of a job.active_start_timeis int, with a default of 000000, which indicates 12:00:00 A.M.on a 24-hour clock, and must be entered using the form HHMMSS.

  • [ @active_end_time = ] active_end_time
    The time on any day between active_start_date and active_end_date to end execution of a job.active_end_timeis int, with a default of 235959, which indicates 11:59:59 P.M.on a 24-hour clock, and must be entered using the form HHMMSS.

  • [ @ owner_login_name= ] "owner_login_name'
    The name of the server principal that owns the schedule.owner_login_name is sysname, with a default of NULL, which indicates that the schedule is owned by the creator.

  • [ @schedule_uid= ] schedule_uidOUTPUT
    A unique identifier for the schedule.schedule_uid is a variable of type uniqueidentifier.

  • [ @schedule_id= ] schedule_idOUTPUT
    An identifier for the schedule.schedule_id is a variable of type int.

  • [ @originating_server= ] server_name
    Identified for informational purposes only. Not supported. Future compatibility is not guaranteed.

Wartości kodów powrotnych

0 (sukces) lub 1 (brak)

Zestawy wyników

None

Remarks

SQL Server Management Studio zapewnia to łatwe, graficzny sposób zarządzania zadaniami i jest zalecanym sposobem tworzenia i zarządzania infrastrukturą zadanie.

Uprawnienia

Domyślnie członkowie sysadmin stała rola serwera możliwość wykonać tej procedura przechowywana.Inni użytkownicy klastrowa musi mieć jedną z następujących czynności SQL Server Agent stałe role bazy danych w msdb bazy danych:

  • SQLAgentUserRole

  • SQLAgentReaderRole

  • SQLAgentOperatorRole

Aby uzyskać szczegółowe informacje o uprawnieniach z tych ról zobacz SQL Server Agent Fixed Database Roles.

Przykłady

A.Formaty wyrażenie ISDATE

W poniższym przykładzie jest tworzony harmonogram o nazwie RunOnce.Zadania ujęte w harmonogramie zostaną wykonane raz, o godzinie 23:30, w dniu utworzenia harmonogramu.

USE msdb ;
GO

EXEC dbo.sp_add_schedule
    @schedule_name = N'RunOnce',
    @freq_type = 1,
    @active_start_time = 233000 ;

GO

B.Tworzenie harmonogramu i dołączanie do niego zadań

Poniższy przykład tworzy harmonogram o nazwie NightlyJobs. Każdego dnia, kiedy czas na serwerze jest wykonać zadania, które używają tego harmonogramu 01:00. W przykładzie dołącza harmonogram dla zadanie BackupDatabase i zadanie RunReports.

Uwaga

W tym przykładzie założono, że zadanie BackupDatabase i zadania RunReports już istnieje.

USE msdb ;
GO

EXEC sp_add_schedule
    @schedule_name = N'NightlyJobs' ,
    @freq_type = 4,
    @freq_interval = 1,
    @active_start_time = 010000 ;
GO


EXEC sp_attach_schedule
   @job_name = N'BackupDatabase',
   @schedule_name = N'NightlyJobs' ;
GO

EXEC sp_attach_schedule
   @job_name = N'RunReports',
   @schedule_name = N'NightlyJobs' ;
GO

Historia zmian

Microsoft Learning

W poniższej tabela zestawiono formaty wprowadzania wyrażenie, które nie są prawidłowe i że powrócić, 0 lub błąd.