Aracılığıyla paylaş


sp_add_job (Transact-SQL)

Yeni bir iş SQLServerAgent hizmet ekler.

Topic link iconTransact-SQL sözdizimi kuralları

sp_add_job [ @job_name = ] 'job_name'
     [ , [ @enabled = ] enabled ] 
     [ , [ @description = ] 'description' ] 
     [ , [ @start_step_id = ] step_id ] 
     [ , [ @category_name = ] 'category' ] 
     [ , [ @category_id = ] category_id ] 
     [ , [ @owner_login_name = ] 'login' ] 
     [ , [ @notify_level_eventlog = ] eventlog_level ] 
     [ , [ @notify_level_email = ] email_level ] 
     [ , [ @notify_level_netsend = ] netsend_level ] 
     [ , [ @notify_level_page = ] page_level ] 
     [ , [ @notify_email_operator_name = ] 'email_name' ] 
          [ , [ @notify_netsend_operator_name = ] 'netsend_name' ] 
     [ , [ @notify_page_operator_name = ] 'page_name' ] 
     [ , [ @delete_level = ] delete_level ] 
     [ , [ @job_id = ] job_id OUTPUT ] 

Bağımsız değişkenler

  • [ @job_name = ] 'job_name'
    Adını iş.The name must be unique and cannot contain the percent (%) character.job_nameis nvarchar(128), with no default.

  • [ @enabled = ] enabled
    Indicates the status of the added job.enabledis tinyint, with a default of 1 (enabled).If 0, iş etkin değil, zamanlamaya göre çalıştır; ancak bunu el ile çalıştırabilirsiniz.

  • [ @description = ] 'description'
    The description of the job.description is nvarchar(512), with a default of NULL.If descriptionolan atlanırsa "Hiçbir açıklama kullanılabilir" kullanılır.

  • [ @start_step_id = ] step_id
    The identification number of the first step to execute for the job.step_idis int, with a default of 1.

  • [ @category_name = ] 'category'
    The category for the job.categoryis sysname, with a default of NULL.

  • [ @category_id = ] category_id
    A language-independent mechanism for specifying a job category.category_idis int, with a default of NULL.

  • [ @owner_login_name = ] 'login'
    The name of the login that owns the job.loginis sysname, with a default of NULL, which is interpreted as the current login name.Yalnızca üyeleri sysadmin sunucu rolünü can sabit küme veya değerini değiştirin.@ owner_login_name.Üye olmayan kullanıcılar, sysadmin rolünü ayarlamak veya değerini değiştirin.@ owner_login_name, yürütme, bu yordamı başarısız saklanan ve bir hata döndürdü.

  • [ @notify_level_eventlog = ] eventlog_level
    A value indicating when to place an entry in the Microsoft Windows application log for this job.eventlog_levelis int, and can be one of these values.

    Değer

    Açıklama

    0

    Hiçbir zaman

    1

    Başarı

    2 (varsayılan)

    Hatası

    3

    Her zaman

  • [ @notify_level_email = ] email_level
    A value that indicates when to send an e-mail upon the completion of this job.email_levelis int, with a default of 0, which indicates never.email_leveluses the same values as eventlog_level.

  • [ @notify_level_netsend = ] netsend_level
    A value that indicates when to send a network message upon the completion of this job.netsend_levelis int, with a default of 0, which indicates never.netsend_level uses the same values as eventlog_level.

  • [ @notify_level_page = ] page_level
    A value that indicates when to send a page upon the completion of this job.page_levelis int, with a default of 0, which indicates never.page_leveluses the same values as eventlog_level.

  • [ @notify_email_operator_name = ] 'email_name'
    The e-mail name of the person to send e-mail to when email_level is reached.email_name is sysname, with a default of NULL.

  • [ @notify_netsend_operator_name = ] 'netsend_name'
    The name of the operator to whom the network message is sent upon completion of this job.netsend_nameis sysname, with a default of NULL.

  • [ @notify_page_operator_name = ] 'page_name'
    The name of the person to page upon completion of this job.page_nameis sysname, with a default of NULL.

  • [ @delete_level = ] delete_level
    A value that indicates when to delete the job.delete_valueis int, with a default of 0, which means never.delete_leveluses the same values as eventlog_level.

    Not

    Ne zaman delete_level olan 3, iş, iş için tanımlanan tüm zamanlamaları ne olursa olsun yalnızca bir kez çalıştırılır.Ayrıca, bir iş kendisini siler, iş için tüm geçmiş de silinir.

  • [ @job_id = ] job_idOUTPUT
    The job identification number assigned to the job if created successfully.job_idis an output variable of type uniqueidentifier, with a default of NULL.

Dönüş Kodu Değerleri

0 (başarılı) veya 1 (hata)

Sonuç Kümeleri

None

Remarks

@ originating_server bulunmaktadır.sp_add_job, ancak olmayan bağımsız değişkenleri altında listelenen.@ originating_server dahili kullanım için ayrılmıştır.

After sp_add_job has been executed to add a job, sp_add_jobstep can be used to add steps that perform the activities for the job.sp_add_jobschedule can be used to create the schedule that the SQL Server Agent service uses to execute the job.Kullanımı sp_add_jobserver to küme the SQL Server Burada, işi yürüten, örnek ve sp_delete_jobserver işi kaldırmak içinSQL Server Örnek.

Iş, bir veya daha fazla hedef sunucularda bir çoklu sunucu ortamı yürüteceğini kullanın sp_apply_job_to_targets , hedef sunucular veya iş için hedef sunucu gruplarını ayarlamak için.Işler, hedef sunucular veya hedef sunucu grupları kaldırmak için kullanın. sp_remove_job_from_targets.

SQL Server Management Studio işleri yönetmek için kolay ve grafiksel bir yol sunar ve oluşturmak ve iş alt yapısı'nı yönetmek için önerilen yöntemdir.

İzinler

Bu saklı yordamı çalıştırmak için , kullanıcıların bir üyesi olmanız sysadmin sabit sunucu rolü veya aşağıdaki birine verilmişSQL Server Aracı bulunması veritabanı rollerini sabit msdb veritabanı:

  • SQLAgentUserRole

  • SQLAgentReaderRole

  • SQLAgentOperatorRole

Bu sabit veritabanı rolü hepsiyle ilişkili belirli izinler hakkında daha fazla bilgi için bkz: SQL Server Agent Database Roles sabit.

Yalnızca üyeleri sysadmin sunucu rolünü can sabit küme veya değerini değiştirin.@ owner_login_name.Üye olmayan kullanıcılar, sysadmin rolünü ayarlamak veya değerini değiştirin.@ owner_login_name, yürütme, bu yordamı başarısız saklanan ve bir hata döndürdü.

Örnekler

C.Bir iş ekleme

Bu örnek, adlı yeni bir iş ekler. NightlyBackups.

USE msdb ;
GO

EXEC dbo.sp_add_job
    @job_name = N'NightlyBackups' ;
GO

b.Çağrı cihazı bir iş eklemek, e-posta ve ağ bilgi gönder

Bu örnek, adlı iş oluşturur. Ad hoc Sales Data Backup size bildirir. François Ajenstat (göre çağrı cihazı, e-posta veya ağ açılan ileti) işi başarısız olursa ve bu iş tamamlandıktan sonra başarılı siler.

Not

Bu örnek bir işleç adlı olduğunu varsayar. François Ajenstat ve bir oturum açma adı françoisa zaten mevcut.

USE msdb ;
GO

EXEC dbo.sp_add_job
    @job_name = N'Ad hoc Sales Data Backup', 
    @enabled = 1,
    @description = N'Ad hoc backup of sales data',
    @owner_login_name = N'françoisa',
    @notify_level_eventlog = 2,
    @notify_level_email = 2,
    @notify_level_netsend = 2,
    @notify_level_page = 2,
    @notify_email_operator_name = N'François Ajenstat',
    @notify_netsend_operator_name = N'François Ajenstat', 
    @notify_page_operator_name = N'François Ajenstat',
    @delete_level = 1 ;
GO