Agar aap SQL Server me automation samajh chuke ho, to next logical step hai SQL Server Agent Jobs aur Schedules ko practically use karna.
Is blog me hum detail me samjhenge:
- Job kya hoti hai
- Job kaise run hoti hai
- Multiple steps kaise kaam karte hain
- Schedule kaise configure karte hain
- GUI se job kaise create karte hain
- Real execution aur troubleshooting
SQL Server Agent Job Kya Hoti Hai?
SQL Server Agent Job ek defined series of actions hoti hai jo SQL Server Agent perform karta hai.
SQL Server Agent, Microsoft SQL Server ka automation engine hai.
Simple words me:
Job = Tasks ka collection
Ek job:
- Ek single task ho sakti hai
- Ya multiple steps ka combination ho sakti hai
Aur important baat:
✔ Job local server par run ho sakti hai
✔ Ya multiple remote servers par bhi run ho sakti hai
Job Kaise Run Hoti Hai? (3 Ways)
SQL Server Agent job ko 3 tarike se run kara sakte hain:
1️⃣ Schedule ke through (Most Common)
Example:
- Daily 10 PM
- Weekly
- Monthly
- Specific date/time
Ye automation ka primary use case hai.
2️⃣ Alert ke Response me
Example:
- TempDB size zyada ho gaya
- Disk space low ho gaya
To automatically ek job run ho sakti hai.
3️⃣ Stored Procedure se Manually
sp_start_job stored procedure use karke manually job trigger kar sakte hain.
Ye useful hota hai:
- Testing ke liye
- Application integration ke liye
Job Steps Kya Hote Hain?
Har job multiple steps se milkar bani hoti hai.
Example:
Ek job me ye 3 steps ho sakte hain:
- T-SQL statement run karna
- SSIS package execute karna
- Analysis Services command run karna
Yaha dhyaan dene wali baat:
Har action = Ek job step
Aur steps sequentially run hote hain.
Job Steps Dependency Logic
Har step ke liye define kar sakte hain:
- Success hone par kya kare?
- Next step pe jaaye?
- Job end kare?
- Failure hone par kya kare?
- Retry kare?
- Job fail kare?
- Next step pe jaaye?
Ye control production jobs me bahut important hota hai.
Security Context of Job Steps
Har job step apne specific security context me run hota hai.
T-SQL Steps
Use:EXECUTE AS
Other Steps (SSIS, Cmd, PowerShell)
Use:
Proxy accounts
Ye ensure karta hai:
✔ Least privilege
✔ Controlled execution
Schedules – Job Kab Run Hogi?
Schedule define karta hai job kab run hogi.
Ek job ke multiple schedules ho sakte hain.
Example:
- 1 PM
- 3 PM
- 5 PM
Schedule options:
- SQL Server Agent start hote hi
- Server idle hone par
- One-time execution
- Recurring (Daily/Weekly/Monthly)
Practical Demo: GUI se Job Create Karna
Ab dekhte hain step-by-step kaise job create karte hain.
Step 1: Check SQL Server Agent Running
SSMS me dekho green icon hai ya nahi.

Ya Configuration Manager me check karo:
SQL Server Agent service running honi chahiye.
Example: Table Truncate Job Create Karna
Hum ek job create karenge jo:
- AdventureWorks database ki table truncate kare
- Daily 10 PM par run ho
(Example database: AdventureWorks)
INSERT INTO ErrorLog (ErrorTime, UserName, ErrorNumber, ErrorSeverity, ErrorState, ErrorProcedure, ErrorLine, ErrorMessage)
SELECT TOP 100
DATEADD(SECOND, -ROW_NUMBER() OVER(ORDER BY (SELECT NULL)), GETDATE()),
'TestUser',
50000 + ROW_NUMBER() OVER(ORDER BY (SELECT NULL)),
16,
1,
'usp_BulkTest',
10,
'Bulk dummy error message'
FROM sys.all_objects a
CROSS JOIN sys.all_objects b;
Step 2: New Job Create Karein
Right click → New Job
General Tab
- Job Name: DBA – Truncate Table
- Owner: System account (best practice)
- Description add karein

⚠ Best Practice:
Individual user ko owner mat rakho. Agar account disable ho gaya to job fail hoga.
Step 3: Add Job Step
Steps tab → New
- Step name: Truncate Table
- Type: T-SQL
- Database select karo
- Command likho:
TRUNCATE TABLE ErrorLog
Parse button se syntax check kar lo.

Step 4: Advanced Settings
Define karo:
On Success:
- Quit job reporting success (agar single step hai)
On Failure:
- Quit job reporting failure
Retry option:
Example:
- 1 retry after 30 minutes

Step 5: Schedule Set Karna
Schedules → New
Options:
- Recurring
- Weekly
- Monday to Friday
- Time: 10 PM
- Start date: Today
- End date: Optional
Schedule enable karna mat bhoolna.

Job Run Aur History Check Karna
Job manually run kar sakte ho:
Right click → Start Job
History dekhne ke liye:
Right click → View History
Yaha milega:
- Success/Failure
- Execution time
- Error details

Multiple Steps Add Karna
Ab maan lo second step add karte hain:
Delete top 1 row from another table.
Important Change:
First step me:
On Success → Go to next step
Second step me:
On Success → Quit job reporting success
Ye control logic bahut important hai.
Real Error Scenario
Agar table name galat likh diya:
Job fail hogi.
History me error milega:
"Invalid object name"
Ye troubleshooting ka main tool hai.
Different Step Types
Job step type change kar sakte ho:
- T-SQL
- Operating System Command
- PowerShell
- SSIS Package
- Replication