Tuesday, June 19, 2007

SQL Code Posting.

OK, this should post with all the appropriate colors and formatting. Let's see, here...



-- Add job script
-- Demonstrating adding a job, with one step
-- scheduling it, and running it, WITHOUT
-- USING ENTERPRISE MANAGER

-- NOTE: This script is for SQL 2000. There is a
-- different method for scheduling in SQL 2005.

-- First, switch to MSDB to create the job

use msdb
go

exec sp_add_job
@job_name = N'TEST: Table copy to DEV_DB',
@enabled = 1,
@description = N'A test job to illustrate job management without SQLEM'
go

-- Now add the step to the job

exec sp_add_jobstep
@job_name = N'TEST: Table copy to DEV_DB',
@step_id = 1,
@step_name = N'Copy Step',
@subsystem = N'TSQL',
@command = N'select * into dev_db..test_users from test_db..test_users',
@server = N'CRPDEVBOX',
@database_name = N'dev_db'
go

-- Target the job to the server...

exec sp_add_jobserver
@job_name = N'TEST: Table copy to DEV_DB',
@server_name = N'CRPDEVBOX'
go

-- Finally, schedule the job.

exec sp_add_jobschedule
@job_name = N'TEST: Table copy to DEV_DB',
@name = N'One time test',
@enabled = 1,
@freq_type = 1,
@active_start_date = 20070410,
@active_start_time = 141500
go

1 comment:

David M Maxwell said...

Hm. Didn't preserve my line breaks, but not too bad. I can tweak that. :-)