gpt4 book ai didi

mysql - 在 ALTER_PROCEDURE DDL 触发器中获取过程名称

转载 作者:行者123 更新时间:2023-11-29 03:18:59 26 4
gpt4 key购买 nike

我制作了一个 SQL 触发器,每当我的数据库中的任何存储过程发生更改时,它都会发送电子邮件警报。我可以在电子邮件中包含 SP 的名称吗?如何调用特定的 SP 名称以显示在电子邮件中?

这是我的代码:

ALTER TRIGGER [send_Email_to_User_ALTER]
ON DATABASE--msdb.dbo.[sp_send_dbmail]
AFTER ALTER_PROCEDURE
AS

--BEGIN
--SET NOCOUNT ON;

EXEC msdb.dbo.[sp_send_dbmail]
@profile_name = 'Test Alert',
@recipients = 'email@outlook.com',
@body = 'A STORED PROCEDURE HAS BEEN ALTERED.' ,
@subject = 'ALERT System SP Change Notification';

最佳答案

试试这个:

ALTER TRIGGER [send_Email_to_User_ALTER] 
ON DATABASE--msdb.dbo.[sp_send_dbmail]
AFTER ALTER_PROCEDURE
AS


--BEGIN
--SET NOCOUNT ON;
DECLARE @data XML
SET @data = EVENTDATA()
DECLARE @objName Nvarchar(max)
SET @objName = (SELECT @data.value('(/EVENT_INSTANCE/ObjectName)[1]', 'nvarchar(256)'))

DECLARE @body NVARCHAR(MAX)
SET @body = 'A STORED PROCEDURE HAS BEEN ALTERED.' + @objName

EXEC msdb.dbo.[sp_send_dbmail]
@profile_name = 'Test Alert',
@recipients = 'email@outlook.com',
@body = @body ,
@subject = 'ALERT System SP Change Notification';

关于mysql - 在 ALTER_PROCEDURE DDL 触发器中获取过程名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48453324/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com