Managing SQL Agent Jobs Across 50+ Servers
By Tom Nonmacher
Managing SQL Agent Jobs across a multitude of servers can be quite a task. However, with the right use of SQL Server 2012 and SQL Server 2014, this task becomes manageable and efficient. The SQL Server Agent is a component of Microsoft SQL Server which is used to execute tasks scheduled within the SQL Server environment. These tasks, defined in SQL Server Agent jobs, can be anything from database maintenance tasks to data extraction and transformation.
Let's start with a basic example of creating a SQL Agent Job using T-SQL in SQL Server 2012. The code would look something like this:
USE msdb ;
EXEC dbo.sp_add_job
@job_name = N'Weekly Sales Data Backup',
@enabled = 1 ,
@description = N'Backs up the sales data every Sunday at 2 A.M.',
@start_step_id = 1,
@notify_level_eventlog = 0,
@notify_level_email = 2,
@notify_level_netsend = 2,
@notify_level_page = 2,
@delete_level= 1,
@category_name = N'[Uncategorized (Local)]',
@owner_login_name = N'sa', ;
Running this script will create a new job named 'Weekly Sales Data Backup'. This job is set to start at step 1 and sends various types of notifications upon completion or failure. Please note that the @delete_level parameter is set to 1, which means the job will be automatically deleted if it fails to run successfully.
However, managing SQL Agent Jobs across multiple servers involves more than just creating jobs. Thankfully, SQL Server 2014 provides the ability to manage and monitor SQL Agent jobs across multiple instances using Central Management Server (CMS). CMS allows DBAs to execute queries and scripts against multiple servers simultaneously, making job management more efficient.
With MySQL 5.6, you can use the Event Scheduler to perform tasks similar to SQL Agent Jobs. An example of creating an event in MySQL is:
CREATE EVENT e_store
ON SCHEDULE EVERY 1 WEEK STARTS '2016-02-02 02:00:00'
DO
BEGIN
INSERT INTO sales_backup SELECT * FROM sales;
END;
This code creates an event that runs every week, starting from 2nd February 2016 at 2 A.M., and copies all data from the 'sales' table into the 'sales_backup' table.
Similarly, for DB2 10.5, you can use the ADMIN_TASK_ADD procedure to schedule routine tasks. While Azure SQL does not have SQL Agent, it does provide Azure Automation that allows scheduling of tasks like T-SQL runbooks which can be used for similar purposes.
In conclusion, managing SQL Agent Jobs across multiple servers can initially be a daunting task, but with the right use of SQL Server tools and features, it can be streamlined and made efficient. The key is understanding the requirements of your environment and leveraging the capabilities of your SQL Server version to the fullest.