Home
%3CLINGO-SUB%20id%3D%22lingo-sub-1180179%22%20slang%3D%22en-US%22%3ERunning%2C%20Scheduling%20and%20Monitoring%20Elastic%20Jobs%20in%20Azure%20SQL%20Database%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1180179%22%20slang%3D%22en-US%22%3E%3CTABLE%20style%3D%22background-color%3A%20transparent%3B%20border-collapse%3A%20collapse%3B%20border-spacing%3A%200px%3B%20box-sizing%3A%20border-box%3B%20color%3A%20%23333333%3B%20font-family%3A%20%26amp%3Bquot%3B%20segoeui%26amp%3Bquot%3B%2C%26amp%3Bquot%3Blato%26amp%3Bquot%3B%2C%26amp%3Bquot%3Bhelvetica%20neue%26amp%3Bquot%3B%2Chelvetica%2Carial%2Csans-serif%3B%20font-size%3A%2016px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20300%3B%20letter-spacing%3A%20normal%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20width%3A%20100%25%3B%20word-spacing%3A%200px%3B%20border-style%3A%20double%3B%22%20border%3D%221%22%20width%3D%22100%25%22%3E%0A%3CTBODY%20style%3D%22box-sizing%3A%20border-box%3B%22%3E%0A%3CTR%20style%3D%22box-sizing%3A%20border-box%3B%22%3E%0A%3CTD%20width%3D%22100%25%22%20style%3D%22border-image-outset%3A%200%3B%20border-image-repeat%3A%20stretch%3B%20border-image-slice%3A%20100%25%3B%20border-image-source%3A%20none%3B%20border-image-width%3A%201%3B%20box-sizing%3A%20border-box%3B%20font-family%3A%20inherit%3B%20font-size%3A%2016px%3B%20font-weight%3A%20300%3B%20line-height%3A%201.7142%3B%20min-width%3A%2040px%3B%20word-break%3A%20normal%3B%20padding%3A%201px%205px%201px%205px%3B%20border%3A%201px%20solid%20%23c4c4c4%3B%22%3E%3CFONT%20style%3D%22box-sizing%3A%20border-box%3B%20color%3A%20%23ff0000%3B%20font-family%3A%20%26amp%3Bquot%3B%20segoeui%26amp%3Bquot%3B%2C%26amp%3Bquot%3Blato%26amp%3Bquot%3B%2C%26amp%3Bquot%3Bhelvetica%20neue%26amp%3Bquot%3B%2Chelvetica%2Carial%2Csans-serif%3B%20font-size%3A%2016px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20300%3B%20letter-spacing%3A%20normal%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%22%20color%3D%22%23ff0000%22%3EElastic%20Jobs%20are%20currently%20in%20public%20preview.%26nbsp%3B%20The%20feature%20is%20ready%20and%20we%20are%20preparing%20to%20make%20it%20officially%20generally%20available.%26nbsp%3B%20No%20extra%20steps%20are%20required%20to%20get%20started.%3C%2FFONT%3E%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3C%2FTBODY%3E%0A%3C%2FTABLE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20previous%20posts%2C%20I%20have%20demonstrated%20how%20to%20create%20an%20Elastic%20Jobs%20Agent%2C%20setup%20credentials%20for%20Elastic%20Jobs%2C%20create%20a%20target%20group%20of%20servers%2Fdatabases%20for%20the%20agent%2C%20and%20how%20to%20create%20and%20define%20an%20elastic%20job%20using%20both%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-sql-database%2Fcreating-an-elastic-jobs-agent-credentials-and-jobs-for-azure%2Fba-p%2F1179929%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3EPowerShell%3C%2FA%3E%20and%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-sql-database%2Fcreating-an-elastic-jobs-agent-credentials-and-jobs-for-azure%2Fba-p%2F1180096%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3ET-SQL%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20this%20post%2C%20I%20drill%20down%20into%20how%20to%20run%20an%20Elastic%20Job%20both%20in%20an%20ad-hoc%20fashion%20and%20how%20to%20schedule%20a%20job%20to%20run%20regularly.%20I%20do%20this%20both%20for%20PowerShell%20and%20for%20T-SQL.%3C%2FP%3E%0A%3CH1%20id%3D%22toc-hId-387876026%22%20id%3D%22toc-hId-387876026%22%3E%26nbsp%3B%3C%2FH1%3E%0A%3CP%3E%3CFONT%20style%3D%22box-sizing%3A%20border-box%3B%20color%3A%20%23333333%3B%20font-family%3A%20%26amp%3Bquot%3B%20segoeui%26amp%3Bquot%3B%2C%26amp%3Bquot%3Blato%26amp%3Bquot%3B%2C%26amp%3Bquot%3Bhelvetica%20neue%26amp%3Bquot%3B%2Chelvetica%2Carial%2Csans-serif%3B%20font-size%3A%2016px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20300%3B%20letter-spacing%3A%20normal%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%22%20color%3D%22%23333333%22%3E%3CSTRONG%20style%3D%22box-sizing%3A%20border-box%3B%20font-weight%3A%20bold%3B%22%3E%3CFONT%20size%3D%225%22%20style%3D%22box-sizing%3A%20border-box%3B%22%3EStarting%20and%20Monitoring%20the%20Job%20Using%20PowerShell%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3EPrerequisites%3C%2FEM%3E%3A%20Azure%20Cloud%20Shell%20or%20PowerShell%20equivalent%2C%20and%20an%20Elastic%20Job%20Agent%20with%20at%20least%20one%20job%20defined.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20first%20step%20at%20this%20point%20is%20to%20get%20and%20bind%20the%20%24jobAgent%20variable%20(to%20get%20the%20job).%26nbsp%3B%20First%2C%20bind%20the%20server%20and%20the%20agent%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3A%5C%26gt%3B%24server%20%3D%20Get-AzSqlServer%20-ServerName%20yourservername%3CBR%20%2F%3E%3A%5C%26gt%3B%24jobAgent%20%3D%20%24server%20%7C%20Get-AzSqlElasticJobAgent%3CBR%20%2F%3E%3A%5C%26gt%3B%24job%20%3D%20%24jobAgent%20%7C%20Get-AzSqlElasticJob%20-Name%20demo123%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3E3%3C%2FFONT%3E%3C%2FPRE%3E%0A%3CP%3E%E2%80%AF%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%2C%20we%20can%20start%20the%20job%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3A%5C%26gt%3B%20%24job%20%7C%20Start-AzSqlElasticJob%26nbsp%3B%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eand%20get%20the%20executions%20of%20it%3A%E2%80%AF%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3A%5C%26gt%3B%20%24je%20%3D%20%24%20jobAgent%20%7C%20Get-AzSqlElasticJobExecution%20-Count%2010%26nbsp%3B%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAssuming%20our%20job%20succeeds%2C%20we%20can%20schedule%20it%20to%20run%20every%20single%20day%2C%20starting%20from%20now.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3A%5C%26gt%3B%20%3CSPAN%3E%24job%3C%2FSPAN%3E%20%7C%20%3CSPAN%3ESet-AzSqlElasticJob%3C%2FSPAN%3E%3CSPAN%3E%20-IntervalType%3C%2FSPAN%3E%20Day%3CSPAN%3E%20-IntervalCount%3C%2FSPAN%3E%20%3CSPAN%3E1%3C%2FSPAN%3E%3CSPAN%3E%20-StartTime%3C%2FSPAN%3E%20(%3CSPAN%3EGet-Date%3C%2FSPAN%3E)%3CSPAN%3E%20-Enable%3C%2FSPAN%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20interval%20types%20allowed%20are%3A%20Day%2C%20Hour%2C%20Minute%2C%20Month%2C%20and%20Week.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20verify%20the%20schedule%2C%20you%20may%20need%20to%20re-bind%20the%20job%20to%20refresh%20it%2C%20then%20just%20re-examine%20%24job%2C%20at%20which%20time%20you%20should%20see%20that%20the%20ScheduleType%20is%20Recurring%20and%20the%20Schedule%20is%20Enabled.%26nbsp%3B%20The%20interval%20is%20for%201%20day.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22RecurringVerifyPowerShell.png%22%20style%3D%22width%3A%20947px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F171885i94EE865D38C24AA7%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22RecurringVerifyPowerShell.png%22%20alt%3D%22RecurringVerifyPowerShell.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20style%3D%22box-sizing%3A%20border-box%3B%20color%3A%20%23333333%3B%20font-family%3A%20%26amp%3Bquot%3B%20segoeui%26amp%3Bquot%3B%2C%26amp%3Bquot%3Blato%26amp%3Bquot%3B%2C%26amp%3Bquot%3Bhelvetica%20neue%26amp%3Bquot%3B%2Chelvetica%2Carial%2Csans-serif%3B%20font-size%3A%2016px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20300%3B%20letter-spacing%3A%20normal%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%22%20color%3D%22%23333333%22%3E%3CSTRONG%20style%3D%22box-sizing%3A%20border-box%3B%20font-weight%3A%20bold%3B%22%3E%3CFONT%20size%3D%225%22%20style%3D%22box-sizing%3A%20border-box%3B%22%3EStarting%20and%20Monitoring%20the%20Job%20Using%20T-SQL%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3EPrerequisites%3C%2FEM%3E%3A%20SQL%20Server%20Management%20Studio%2C%20%3CSPAN%20style%3D%22display%3A%20inline%20!important%3B%20float%3A%20none%3B%20background-color%3A%20%23ffffff%3B%20color%3A%20%23333333%3B%20cursor%3A%20text%3B%20font-family%3A%20inherit%3B%20font-size%3A%2016px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20300%3B%20letter-spacing%3A%20normal%3B%20line-height%3A%201.7142%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%22%3Eand%20an%20Elastic%20Job%20Agent%20with%20at%20least%20one%20job%20defined.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20can%20explicitly%20start%20the%20job%20in%20an%20ad-hoc%20fashion%20by%20simply%20passing%20the%20job%20name%20as%20an%20argument%20to%20a%20the%20stored%20procedure%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsql-database%2Felastic-jobs-tsql%23sp_start_job%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ejobs.sp_start_job%3C%2FA%3E%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3EEXEC%20jobs.sp_start_job%20'demo123'%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20schedule%20the%20job%20to%20run%20every%20day%2C%20use%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsql-database%2Felastic-jobs-tsql%23sp_update_job%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ejobs.sp_update_job%3C%2FA%3E%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3EEXEC%20jobs.sp_update_job%3CBR%20%2F%3E%40job_name%20%3D%20'demo123'%2C%3CBR%20%2F%3E%40enabled%3D1%2C%3CBR%20%2F%3E%40schedule_interval_type%3D'day'%2C%3CBR%20%2F%3E%40schedule_interval_cout%3D1%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20want%20to%20verify%20that%20the%20job%20is%20scheduled%2C%20query%20the%20table%20jobs.jobs%20in%20the%20database%20where%20the%20Elastic%20Job%20Agent%20is%20hosted%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3ESELECT%20*%20FROM%20jobs.jobs%20WHERE%20job_name%20%3D%20'demo123'%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22QueryJobRecurrenceInSSMS.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F172091i7FB19150D1B2A029%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22QueryJobRecurrenceInSSMS.png%22%20alt%3D%22QueryJobRecurrenceInSSMS.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnother%20way%20to%20verify%20the%20job%20and%20schedule%20is%20to%20examine%20it%20through%20the%20Azure%20Portal.%20To%20do%20this%2C%20find%20all%20of%20your%20Elastic%20Job%20Agents%20(you%20can%20search%20for%20the%20Elastic%20Job%20Agents%20service%20in%20the%20search%20bar%20at%20the%20top%20of%20the%20home%20page%20on%20the%20Azure%20Portal)%2C%20and%20then%20select%20your%20agent.%20From%20there%2C%20you%20can%20drill%20down%20into%20the%20jobs%2C%20find%20the%20target%20job%2C%20and%20view%20its%20schedule.%26nbsp%3B%20Below%20you%20will%20see%20a%20job%20with%20an%20enabled%20daily%20schedule.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22JobScheduledAzurePortal.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F171886i70B74057BC5C98BB%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22JobScheduledAzurePortal.png%22%20alt%3D%22JobScheduledAzurePortal.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20blog%20is%20part%20of%20a%20series%20about%20Elastic%20Jobs%20on%20Azure%20SQL%20Database.%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-sql-database%2Felastic-jobs-in-azure-sql-database-what-and-why%2Fba-p%2F1177902%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3EElastic%20Jobs%20in%20Azure%20SQL%20Database%20%E2%80%93%20What%20and%20Why%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-sql-database%2Ffundamental-concepts-for-elastic-jobs-in-azure-sql-database%2Fba-p%2F1177939%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3EFundamental%20Concepts%20for%20Elastic%20Jobs%20in%20Azure%20SQL%20Database%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-sql-database%2Fcreating-an-elastic-jobs-agent-credentials-and-jobs-for-azure%2Fba-p%2F1179929%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3ECreating%20an%20Elastic%20Jobs%20Agent%2C%20Credentials%2C%20and%20Jobs%20for%20Azure%20SQL%20Database%20in%20PowerShell%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-sql-database%2Fcreating-an-elastic-jobs-agent-credentials-and-jobs-for-azure%2Fba-p%2F1180096%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3ECreating%20an%20Elastic%20Jobs%20Agent%2C%20Credentials%2C%20and%20Jobs%20for%20Azure%20SQL%20Database%20using%20T-SQL%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-sql-database%2Frunning-scheduling-and-monitoring-elastic-jobs-in-azure-sql%2Fba-p%2F1180179%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3ERunning%2C%20Scheduling%20and%20Monitoring%20Elastic%20Jobs%20in%20Azure%20SQL%20Database%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-sql-database%2Ftroubleshooting-common-issues-with-elastic-jobs-in-azure-sql%2Fba-p%2F1180766%22%20target%3D%22_self%22%3ETroubleshooting%20Common%20issues%20with%20Elastic%20Jobs%20in%20Azure%20SQL%20Database%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FOL%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1180179%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20this%20post%2C%20I%20drill%20down%20into%20how%20to%20run%20an%20Elastic%20Job%20both%20in%20an%20ad-hoc%20fashion%20and%20how%20to%20schedule%20a%20job%20to%20run%20regularly.%20I%20do%20this%20both%20for%20PowerShell%20and%20for%20T-SQL.%3C%2FP%3E%3C%2FLINGO-TEASER%3E
Microsoft
Elastic Jobs are currently in public preview.  The feature is ready and we are preparing to make it officially generally available.  No extra steps are required to get started.

 

In previous posts, I have demonstrated how to create an Elastic Jobs Agent, setup credentials for Elastic Jobs, create a target group of servers/databases for the agent, and how to create and define an elastic job using both PowerShell and T-SQL.

 

In this post, I drill down into how to run an Elastic Job both in an ad-hoc fashion and how to schedule a job to run regularly. I do this both for PowerShell and for T-SQL.

 

Starting and Monitoring the Job Using PowerShell

Prerequisites: Azure Cloud Shell or PowerShell equivalent, and an Elastic Job Agent with at least one job defined.

 

The first step at this point is to get and bind the $jobAgent variable (to get the job).  First, bind the server and the agent:

 

:\>$server = Get-AzSqlServer -ServerName yourservername
:\>$jobAgent = $server | Get-AzSqlElasticJobAgent
:\>$job = $jobAgent | Get-AzSqlElasticJob -Name demo1233

  

Now, we can start the job:

 

:\> $job | Start-AzSqlElasticJob 

 

and get the executions of it:  

 

:\> $je = $ jobAgent | Get-AzSqlElasticJobExecution -Count 10 

 

Assuming our job succeeds, we can schedule it to run every single day, starting from now.

 

:\> $job | Set-AzSqlElasticJob -IntervalType Day -IntervalCount 1 -StartTime (Get-Date) -Enable

 

The interval types allowed are: Day, Hour, Minute, Month, and Week.

 

To verify the schedule, you may need to re-bind the job to refresh it, then just re-examine $job, at which time you should see that the ScheduleType is Recurring and the Schedule is Enabled.  The interval is for 1 day. 

RecurringVerifyPowerShell.png

 

Starting and Monitoring the Job Using T-SQL

Prerequisites: SQL Server Management Studio, and an Elastic Job Agent with at least one job defined.

 

We can explicitly start the job in an ad-hoc fashion by simply passing the job name as an argument to a the stored procedure jobs.sp_start_job:

 

EXEC jobs.sp_start_job 'demo123'

 

To schedule the job to run every day, use jobs.sp_update_job:

 

EXEC jobs.sp_update_job
@job_name = 'demo123',
@enabled=1,
@schedule_interval_type='day',
@schedule_interval_cout=1

 

If you want to verify that the job is scheduled, query the table jobs.jobs in the database where the Elastic Job Agent is hosted:

 

SELECT * FROM jobs.jobs WHERE job_name = 'demo123'

 

QueryJobRecurrenceInSSMS.png

 

Another way to verify the job and schedule is to examine it through the Azure Portal. To do this, find all of your Elastic Job Agents (you can search for the Elastic Job Agents service in the search bar at the top of the home page on the Azure Portal), and then select your agent. From there, you can drill down into the jobs, find the target job, and view its schedule.  Below you will see a job with an enabled daily schedule.

 

JobScheduledAzurePortal.png

 

This blog is part of a series about Elastic Jobs on Azure SQL Database.

  1. Elastic Jobs in Azure SQL Database – What and Why
  2. Fundamental Concepts for Elastic Jobs in Azure SQL Database
  3. Creating an Elastic Jobs Agent, Credentials, and Jobs for Azure SQL Database in PowerShell
  4. Creating an Elastic Jobs Agent, Credentials, and Jobs for Azure SQL Database using T-SQL
  5. Running, Scheduling and Monitoring Elastic Jobs in Azure SQL Database
  6. Troubleshooting Common issues with Elastic Jobs in Azure SQL Database