jac*_*ack 4 sql-server sql-server-agent alerts operator
我想向 SQL 代理操作员警报添加超过 100 个字符的电子邮件地址。
例如: emaione@example.com;emailtwo@example.com;emailthree@example.com;....
我试图通过改变 sysoperators email_address 列来绕过 100 个字符的限制
ALTER TABLE sysoperators
ALTER column email_address NVARCHAR(1000);
Run Code Online (Sandbox Code Playgroud)
然后创建我的运算符,但地址仍然被截断为 100 个字符?
仅仅因为你可以并不意味着你应该。请不要应用以下更改。这个答案只是为了向您展示为什么不应该更改系统表或系统过程以及可能出错的地方。
msdb.dbo.sp_add_operator
添加带有 ssms gui 的操作符时,msdb.dbo.sp_add_operator
在幕后调用。
使用的电子邮件地址参数也是nvarchar(100)
.
理论上,您可以通过更改程序来调整程序
然后将@email_address
参数更改为nvarchar(1000)
如果我然后用 384 个字符(非 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
Run Code Online (Sandbox Code Playgroud)
获取长度:
select LEN(email_address) as email_length
from sysoperators
where name = 'test';
Run Code Online (Sandbox Code Playgroud)
显示有 384 个字符。
email_length
384
Run Code Online (Sandbox Code Playgroud)
但是,当通过 ssms 打开操作员列表时,立即破坏的一件事是:
由于 ssms 运行此查询:
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
Run Code Online (Sandbox Code Playgroud)
说明为什么我们应该不玩弄系统表和程序。
谁知道在改变表格和程序时什么会起作用,什么会破坏。
vonPryz提到的分发列表将是一个更好的解决方案。