To determine the total number of transactions committed in Azure SQL Server (or Azure SQL Database) over the last 24 hours, the most reliable and supported approach is to leverage Azure Monitor Logs (Log Analytics). Here's a structured breakdown of how to achieve this, along with limitations of alternative methods.
✅ Recommended Solution: Azure Monitor Logs (Log Analytics)
Azure SQL Database emits transaction metrics that can be queried using Azure Monitor Logs (requires a Log Analytics workspace linked to your SQL server). This method provides historical data and allows aggregation over time.
Steps to Query Transaction Count in the Last 24 Hours
-
Navigate to Azure Monitor Logs:
- Go to the Azure Portal.
- Open Monitor > Logs.
- Select the Log Analytics workspace associated with your Azure SQL server.
-
Run the Kusto Query:
Use the following query to retrieve the total number of transactions over the last 24 hours:
AzureMetrics
| where Resource contains "your-sql-server-name"
| where MetricName == "transaction"
| where TimeGenerated >= ago(24h)
| summarize TotalTransactions = sum(Count)
- Replace
"your-sql-server-name" with the actual name of your Azure SQL server (e.g., my-sql-server.database.windows.net).
- The
Count column represents the number of transactions in each time interval.
- The
summarize operator aggregates the total transactions over the 24-hour period.
-
Interpret the Result:
- The output will be a single value representing the total number of transactions committed in the last 24 hours.
⚠️ Alternative Methods and Their Limitations
1. Using sys.dm_os_performance_counters
You can query the sys.dm_os_performance_counters DMV to get the total number of transactions since the server started:
SELECT cntr_value
FROM sys.dm_os_performance_counters
WHERE counter_name = 'Total Transactions';
- Limitation: This gives the cumulative count since the last restart. Without historical data, you cannot determine the number of transactions in the last 24 hours unless you have a baseline from 24 hours ago.
2. Using sys.dm_tran_transaction_stats
This DMV provides transaction statistics, including committed snapshot transactions:
SELECT committed_snapshot_transactions
FROM sys.dm_tran_transaction_stats;
- Limitation: This only tracks snapshot isolation transactions, not all committed transactions. Also, it does not provide historical data.
3. Using Azure Portal Metric Charts
You can view the Transaction metric in the Azure Portal:
-
Go to your SQL database > Monitoring > Metrics.
-
Select the Transaction metric and set the time range to the last 24 hours.
-
Choose Sum as the aggregation type.
-
Limitation: While this visualizes the data, it doesn’t provide a direct count. You would need to manually sum the values or use Log Analytics for automation.
🛠️ Best Practice: Set Up Continuous Monitoring
To track transaction counts over time, consider setting up a scheduled job or using Azure Logic Apps or Azure Functions to log data from sys.dm_os_performance_counters or the Azure Monitor Logs query into a storage account or database.
📝 Summary
| Method | Feasibility | Notes |
|---|
| Azure Monitor Logs (Log Analytics) | ✅ Recommended | Provides accurate historical data |
| sys.dm_os_performance_counters | ⚠️ Limited | Only cumulative count since restart |
| sys.dm_tran_transaction_stats | ⚠️ Limited | Only snapshot transactions, no historical data |
| Azure Portal Metrics | ⚠️ Manual | Visual only, not suitable for programmatic use |
🔗 Additional Resources
By using Azure Monitor Logs, you can efficiently retrieve the total number of transactions committed in the last 24 hours for your Azure SQL server. For long-term monitoring, consider setting up a logging or alerting mechanism to capture this data regularly.