SQL Server Audit and Security Alerting for Privileged Login Activities
Purpose
This solution implements a Server-Level DDL Trigger in SQL Server to monitor privileged login-related activities in real time. Whenever a login is created, modified, or dropped, the trigger automatically captures activity details and sends HTML-formatted email notifications to DBA, Security, Audit, and SOC teams.
The solution enhances security monitoring, strengthens audit controls, and provides immediate visibility into privileged access changes within SQL Server.
Events Monitored
| Event | Description |
|---|---|
| CREATE_LOGIN | Triggered whenever a new SQL Server login is created. |
| ALTER_LOGIN | Triggered whenever an existing login is modified, enabled, disabled, or renamed. |
| DROP_LOGIN | Triggered whenever a login is removed from the SQL Server instance. |
Trigger Security
The trigger is created using WITH ENCRYPTION, preventing users from viewing the source code through OBJECT_DEFINITION(), sp_helptext, or system catalog views.
Information Captured
| Field | Description |
|---|---|
| Activity Type | CREATE_LOGIN, ALTER_LOGIN, DROP_LOGIN |
| Login Name | Affected Login Account |
| Executed By | Login Account Executing the Command |
| SQL Instance Name | Target SQL Server Instance |
| Host Name | Workstation or Server Name |
| Client IP Address | Source IP Address |
| Application Name | SSMS, SQLCMD, PowerShell, Application Connection, etc. |
| SPID | SQL Server Session ID |
| Date & Time | Timestamp of Activity |
| Executed Command | Actual T-SQL Statement Executed |
Email Notification Process
When a login-related event occurs, the trigger generates an HTML email containing complete audit information including login details, source workstation, IP address, application name, execution account, and the T-SQL command executed.
Email Distribution
| Recipient Type | Purpose |
|---|---|
| To | Primary DBA Team |
| CC | Security and Audit Teams |
| BCC | SOC / Monitoring Teams |
Email Priority Settings
- Importance: HIGH
- Sensitivity: CONFIDENTIAL
Alert Severity Levels
| Event | Severity | Email Subject |
|---|---|---|
| CREATE_LOGIN | HIGH | [HIGH] SQL Audit Alert – New Privileged Login Created |
| ALTER_LOGIN | HIGH | [HIGH] SQL Audit Alert – Privileged Login Modified |
| DROP_LOGIN | CRITICAL | [CRITICAL] SQL Audit Alert – Privileged Login Dropped |
Trigger Script
Execute the following script in the master database to create the Server-Level DDL Trigger.
Benefits
- Real-time monitoring of privileged login activities.
- Immediate notification to DBA, Security, Audit, and SOC teams.
- Supports security auditing and compliance requirements.
- Captures workstation name, client IP address, and application details.
- Provides complete visibility into login-related changes.
- Enhances forensic investigations and incident response activities.
- Helps identify unauthorized or unexpected privileged access changes.
Sample Email Subject Lines
[HIGH] SQL Audit Alert – New Privileged Login Created
[HIGH] SQL Audit Alert – Privileged Login Modified
[CRITICAL] SQL Audit Alert – Privileged Login Dropped
Architecture Diagram of SQL Login Alerts
Conclusion
This solution provides a lightweight yet effective mechanism for monitoring privileged login activities within SQL Server. By combining Server-Level DDL Triggers, Database Mail, HTML-based notifications, and detailed audit information, organizations can significantly improve visibility, accountability, and security governance across SQL Server environments.
![]()