Change character limit of SQL Agent Operators
-
22-02-2021 - |
Question
I want to add more than 100 characters worth of email addresses to the SQL Agent Operators alerting.
For example: emaione@example.com;emailtwo@example.com;emailthree@example.com;....
I tried to get around the 100 character limit by altering sysoperators email_address column as such
ALTER TABLE sysoperators
ALTER column email_address NVARCHAR(1000);
and then creating my operator, but the addresses are still cut off at 100 characters?
La solution
Just because you can does not mean you should. Please do not apply the changes below. This answer is only to show you why you should not change system tables or system procedures and what can go wrong.
msdb.dbo.sp_add_operator
When adding the operator with the ssms gui, msdb.dbo.sp_add_operator
is called behind the scenes.
The email address parameter used is also nvarchar(100)
.
In theory, you could adapt the procedure by altering it
And then changing the @email_address
parameter to nvarchar(1000)
If I then run it wih 384 characters (non gui)
USE [msdb]
GO
EXEC msdb.dbo.sp_add_operator @name=N'test',
@enabled=1,
@pager_days=0,
@email_address=N'emaione@example.com;emailtwo@example.com;emailthree@example.com;emaione@example.com;emailtwo@example.com;emailthree@example.com;emaione@example.com;emailtwo@example.com;emailthree@example.com;emaione@example.com;emailtwo@example.com;emailthree@example.com;emaione@example.com;emailtwo@example.com;emailthree@example.com;emaione@example.com;emailtwo@example.com;emailthree@example.com;'
GO
Getting the length:
select LEN(email_address) as email_length
from sysoperators
where name = 'test';
Shows the 384 characters are there.
email_length
384
However, one of the things instantly breaking is the operator list when opening it via ssms:
Due to ssms running this query:
create table #tmp_sp_help_operator
(id int null, name nvarchar(128) null, enabled tinyint null, email_address nvarchar(100) null, last_email_date int null, last_email_time int null, pager_address nvarchar(100) null, last_pager_date int null, last_pager_time int null, weekday_pager_start_time int null, weekday_pager_end_time int null, saturday_pager_start_time int null, saturday_pager_end_time int null, sunday_pager_start_time int null, sunday_pager_end_time int null, pager_days tinyint null, netsend_address nvarchar(100) null, last_netsend_date int null, last_netsend_time int null, category_name nvarchar(128) null)
insert into #tmp_sp_help_operator exec msdb.dbo.sp_help_operator
SELECT
tsho.name AS [Name],
'Server[@Name=' + quotename(CAST(
serverproperty(N'Servername')
AS sysname),'''') + ']' + '/JobServer' + '/Operator[@Name=' + quotename(tsho.name,'''') + ']' AS [Urn],
CAST(tsho.enabled AS bit) AS [Enabled]
FROM
#tmp_sp_help_operator AS tsho
ORDER BY
[Name] ASC
drop table #tmp_sp_help_operator
Showing why we should not play around with system tables & procedures.
Who knows what will work and what will break when changing the table & the procedure.
A distribution list as vonPryz mentioned would be a much better solution.