我需要在表格上创建一个触发器 -
sp_send_dbmail
触发器必须能够容纳同时更改的多行。
到目前为止,我有以下内容,但它会在将内容添加到日志表之前发送电子邮件。
CREATE TRIGGER [dbo].[trgAfterUpdate]
ON [dbo].[Card]
AFTER UPDATE
AS
IF UPDATE (expiryDate)
BEGIN
INSERT INTO expiryDateChanges (cardID, dateChanged)
SELECT Inserted.cardID, GETDATE()
FROM Inserted;
EXEC msdb.dbo.sp_send_dbmail @profile_name = 'test' ,
@recipients = 'test@test.co.uk' ,
@subject = N'Expiry Date has been changed' ,
@query = 'SELECT cardID
FROM expiryDateChanges
WHERE CAST(dateChanged AS DATE) = CAST(GETDATE() AS DATE)'
END