Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to create a scheduled job on SQL Server 2005?

Author  Topic 

cvvikram
Starting Member

1 Post

Posted - 2007-11-08 : 13:55:55
Hi guys,

Any assistance you guys can provide will be considered grateful. I’m in search of a generic cookie cutter snippet of code that simulates the creation of an Oracle DBMS_JOB, but I need it for SQL Server 2005.

Beneath, highlighted in red, is how we create a DBMS_JOB in Oracle, but I need the snippet of code to accomplish the same objective on SQL Server 2005. In Oracle, we deploy our scheduled jobs using anonymous pl/sql which is written in black, as shown beneath. To facilitate conversion of my project scheduled task it would be great if someone can assist me in translating the code beneath written in black and red.



REM spool schedule-jobs_a.sql.log

REM declare

REM jobno NUMBER;

REM cursor job_cur is select job from user_jobs

REM where what like 'dbms_utility.analyze_schema%';

REM begin

REM

REM for job_rec in job_cur loop

REM dbms_job.remove(job_rec.job);

REM

REM end loop;

REM dbms_job.submit(jobno,what => 'dbms_utility.analyze_schema(''&&anal'',''compute'');', interval => 'TO_DATE(SUBSTR(TO_CHAR(TRUNC(SYSDATE+1)),1,10)) + 360/1440', next_date => SYSDATE);
REM dbms_output.put_line( 'Next job '||jobno );

REM exception

REM when others then raise;

REM end;

REM /





PS, I’m not looking for instructions to create a Scheduled Job through Microsoft SQL Server Management Studio, but rather, I need T-SQL code to create a Schedule Job to run daily at some period of time and run some snippet of code.

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-11-08 : 14:14:16
You can script out the job and save the sql to a file? or did I not understand what you are asking?

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-11-08 : 14:14:52
Manually create the job via the GUI. Then you can script it out via the GUI to see what code will be needed to create a job. There are a ton of commands, so it's not something that we are going to type out here.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -