🚨 Automate SQL Server Alerts to Microsoft Teams (2 Easy Ways)

If you’re a DBA, developer, or IT lead tired of missing key SQL Server issues — you’re not alone. Fortunately, it’s easy to pipe alerts directly into a Microsoft Teams channel in real time.

Here’s a step-by-step guide showing two ways to do it:

  • ✅ Using Power Automate
  • ✅ Or a simpler method using Teams’ built-in channel email

🛠️ Step 1: Enable and Configure Database Mail

First, make sure Database Mail is enabled on your SQL Server.

EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'Database Mail XPs', 1;
RECONFIGURE;

Then go to SSMS → Management → Database Mail, and create a new mail profile with your SMTP info.


🔔 Step 2: Create a SQL Alert Script

Here’s a basic example that checks for over 100 pending orders and sends an alert:

DECLARE @count INT;
SELECT @count = COUNT(*) FROM dbo.Orders WHERE Status = 'Pending';

IF @count > 100
BEGIN
    EXEC msdb.dbo.sp_send_dbmail
        @profile_name = 'DBA_Alerts',
        @recipients = 'your_email@example.com',
        @subject = '🚨 High Pending Orders',
        @body = 'There are more than 100 pending orders in the system.';
END

You can adapt this logic for any metric or threshold that matters to your team.

🔄 Option 1: Send SQL Alerts to Microsoft Teams with Power Automate

Want more control and richer notifications? Power Automate is your friend.

🔧 How to Set It Up:

  1. Go to Power Automate
  2. Create an Automated Cloud Flow
  3. Trigger: When a new email arrives (V3)
  4. Add a condition: Filter by subject line (e.g., contains “High Pending Orders”)
  5. Action: Post a message in a Teams channel
  6. Choose your Team and Channel → Format the message
  7. Save & test

That’s it — your SQL alerts are now flowing into Teams with full control and flexibility.


✉️ Option 2: Send Directly to a Teams Channel via Email (No Power Automate)

Don’t want to mess with Power Automate? No problem.

Microsoft Teams channels have hidden email addresses you can send to directly.

📨 Here’s how:

  1. In Teams, go to the channel you want to alert (like #sql-alerts)
  2. Click the three dots > select “Get email address”
  3. Copy that email (looks like alerts@groupname.teams.ms)
  4. Update your SQL script to send directly to it:
EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'DBA_Alerts',
    @recipients = 'yourchannel@domain.teams.ms',
    @subject = '🚨 SQL Alert: High Pending Orders',
    @body = 'There are more than 100 pending orders in the database as of ' 
          + CONVERT(VARCHAR, GETDATE(), 120);

No additional tools or licenses required — and it shows up directly in the channel.


🆚 Power Automate vs Direct Email — Which Should You Use?

FeaturePower AutomateTeams Email
Setup ComplexityModerateVery Easy
Custom Logic & Routing✅ Yes❌ Limited
CostFree tier (but M365 needed)Free
Good ForAdvanced use casesFast setup or prototyping

✅ Wrap-Up

With either method, your SQL Server can alert your team to problems in real time — no more digging through logs or missed issues.

Use this system to notify your team about:

  • ⚠️ Blocking sessions
  • ⌛ Long-running queries
  • 💾 Backup failures
  • 📊 Custom metric thresholds

All without ever leaving SSMS.


Discover more from SQLYARD

Subscribe to get the latest posts sent to your email.

Leave a Reply

Discover more from SQLYARD

Subscribe now to keep reading and get access to the full archive.

Continue reading