title: SQL Server : scheduling programmatically
body: <p>I'm trying to force SQL Server to call a needed stored procedure each hour.</p>
  
  <p>I've read the following articles:</p>
  
  <ul>
  <li><a href="http://msdn.microsoft.com/en-us/library/ms190268.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms190268.aspx</a></li>
  <li><a href="http://msdn.microsoft.com/en-us/library/ms187320.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms187320.aspx</a></li>
  </ul>
  
  <p>They are quite big and not very straight forward. </p>
  
  <p>Can anyone confirm that the following SQL code is right for my task:</p>
  
  <pre><code>USE msdb ;
  GO
  EXEC dbo.sp_add_job
      @job_name = N'Exec RemoveOldCsvImportData' ;
  GO
  EXEC sp_add_jobstep
      @job_name = N'Exec RemoveOldCsvImportData',
      @step_name = N'execute stored procedure',
      @subsystem = N'TSQL',
      @command = N'exec RemoveOldCsvImportData', 
      @retry_attempts = 5,
      @retry_interval = 5 ;
  GO
  EXEC dbo.sp_add_schedule
      @schedule_name = N'RunOnce',
      @freq_type = 4,
      @freq_interval = 1,
      @freq_subday_type = 0x8,
      @freq_subday_interval = 1,
      @active_start_time = 233000 ;
  USE msdb ;
  GO
  EXEC sp_attach_schedule
     @job_name = N'Exec RemoveOldCsvImportData',
     @schedule_name = N'RunOnce';
  GO
  EXEC dbo.sp_add_jobserver
      @job_name = N'Exec RemoveOldCsvImportData';
  GO 
  </code></pre>