A script works when you run it manually, then nothing happens overnight. SQL Server Agent basics turn that script into a job with steps, a schedule, an execution identity, and history you can review.

SQL Server Agent Basics: What a Job Contains
A SQL Server Agent job is a container for one or more steps. Each step has a subsystem, command, database context, success action, and failure action. The job can be triggered by a schedule or run manually. SQL Server Agent must be available and running on the edition and instance. SQL Server Express does not include it.
I begin with a read-only inventory of existing jobs. Names and owners show how the team organizes work. A job named nightly task tells little about purpose. Which job would you trust to run after a restart without a person watching? That is the standard for a useful first job.
SELECT name, enabled, owner_sid, date_created
FROM msdb.dbo.sysjobs
ORDER BY name;Apply SQL Server Agent Basics to a Small First Job
Choose a harmless check with a clear outcome, such as recording backup recency or validating a known configuration. Do not start by scheduling a destructive cleanup. Write the T-SQL as a tested script first, including database context and error handling. Then put it in a job step. A job does not make unsafe SQL safer.
I use a name that says what the job checks and which environment it belongs to. Set an owner who will remain valid if a person changes teams. Review the account under which the step actually runs. A successful manual execution under sysadmin does not prove the Agent step has the same permissions.
In a test instance, this job checks whether any online user database lacks PAGE_VERIFY CHECKSUM. The step raises an error if it finds one, so job history shows failure. Choose the schedule and notification route that match your operations policy before using it beyond the lab. A failed job is actionable only when somebody receives and investigates the failure.
USE msdb;
GO
EXEC dbo.sp_add_job
@job_name = N'Check User Database Page Verification',
@enabled = 1,
@description = N'Flags online user databases without CHECKSUM';
EXEC dbo.sp_add_jobstep
@job_name = N'Check User Database Page Verification',
@step_name = N'Find non-CHECKSUM databases',
@subsystem = N'TSQL',
@database_name = N'master',
@command = N'IF EXISTS
(SELECT 1 FROM sys.databases
WHERE database_id > 4
AND state_desc = ''ONLINE''
AND page_verify_option_desc <> ''CHECKSUM'')
THROW 51000, ''Review database PAGE_VERIFY settings.'', 1;';
EXEC dbo.sp_add_jobschedule
@job_name = N'Check User Database Page Verification',
@name = N'Daily Page Verification Check',
@freq_type = 4,
@freq_interval = 1,
@active_start_time = 70000;
EXEC dbo.sp_add_jobserver
@job_name = N'Check User Database Page Verification';Set Step Flow Deliberately
For each step, decide what happens on success and failure. A backup step should not flow to a file cleanup step after a failure. A validation failure should stop the job with a message that names the condition. Keep the number of steps small enough that history makes sense. If a workflow has complex branching, a dedicated script with logging can be clearer.
I test the failure path in a disposable environment. Trigger a known error and confirm that job history reports failure. A green job outcome after a failed inner command is a dangerous illusion. The command line tools used inside a job also need nonzero exit behavior.

Choose a Schedule That Fits the Work
A schedule defines when the job starts, not whether its work finished or succeeded. Check time zone, daylight-saving changes, and overlap with backups and maintenance. Decide what happens when the service was stopped during a scheduled run. Use monitoring to detect missed runs rather than assuming the scheduler will repair every gap.
I compare the expected duration with the interval before the next start. Overlapping executions can compete for resources or touch the same files. Which jobs share a database or volume? Put that on the weekly calendar. A schedule is a workload design choice, not just a clock setting.
Use Proxies for the Right Subsystem
Agent steps can run under different security contexts depending on subsystem and configuration. A proxy can allow a step to use a specific credential with controlled access rather than giving the Agent service account broad rights. Configure credentials and proxies through the approved security process. Keep secrets out of job command text.
I ask whether the step needs to write a file, call an external program, or only execute T-SQL. Those actions need different permissions and review. A proxy is not a way to bypass least privilege. It is a way to make the intended identity explicit and auditable.
Read Job History With Context
Job history records outcomes for jobs and steps. Review both. A job can report failure at one step while earlier steps changed data. A successful final step does not prove the underlying business check was correct unless the script raised errors properly. Retention of job history is limited, so important operational results need a durable log or monitoring system.
The query below shows recent job outcomes. Step zero is the overall job result. Use it with step-level details when a run fails. I include the run time and message in the incident note.
SELECT TOP (30) j.name AS job_name,
h.run_date, h.run_time, h.run_status, h.message
FROM msdb.dbo.sysjobhistory AS h
JOIN msdb.dbo.sysjobs AS j ON j.job_id = h.job_id
WHERE h.step_id = 0
ORDER BY h.instance_id DESC;Check SQL Server Agent Basics on the First Useful Run
Create the job through a reviewed script or the SSMS interface, run it manually, and inspect step output. Then let the schedule trigger it and confirm the expected result. Set an alert owner for failure. Document the job’s purpose, permissions, schedule, input, output, and safe retry behavior.
I review it after a service account or server move. Jobs can depend on paths and credentials that do not migrate with a database backup. A first useful job is one that another DBA can explain and recover, not merely one with a green icon.
For a first useful Agent job, choose a read-only check with an observable result, such as reporting databases that have not had a recent full backup. Confirm the job owner, execution context and notification path. A job that runs successfully but sends its warning nowhere is a small scheduling demonstration, not monitoring. I review the job history after the first manual run and again after its scheduled run.
Schedules need a time-zone and overlap decision. If a check takes longer than expected, should a second run start? If the server is down during the window, how will the missed run be noticed? SQL Server Agent basics start with one fact: it is a scheduler and execution host, so it needs the same operational questions as any other automation. Keep the first job narrow enough that failure is easy to understand.
I save the job definition and expected output with the database operations documentation. When a new DBA inherits the instance, that record explains why the job exists and which result demands action. A green Agent icon alone is not an assurance that the important work happened.
Related reading on this blog: SQL Agent Alerts Every Instance Should Have and Automating Backups With SQL Agent and Checking They Worked.

An Agent schedule is not proof of work, it is a trigger whose result must be checked.
Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.




