Use T-SQL to view database, elastic pool, or SQL managed instance properties
| Product family | Azure SQL |
|---|---|
| Document source | Azure SQL |
| Guide type | Hands-on Reference |
| Skill level | Intermediate to advanced |
| Time | 20 - 75 minutes depending on tenant scale |
Inventorying your Azure SQL footprint with T-SQL is fast, reliable, and doesn't require any portal access. I run this query monthly across my managed estate to catch tier drift, region drift, and orphaned databases nobody remembers paying for.
The DMV surface is the same on Database, Elastic Pool, and Managed Instance — with small differences. Knowing which DMVs are universal and which are tier-specific saves you from the "this query works on prod but not on dev" trap.
Reference content and what it actually means
The Microsoft Learn page for Use T-SQL to view database, elastic pool, or SQL managed instance properties treats this as a reference doc. That is fine for "what does this mean." It is not enough for "should I enable this on my tenant tomorrow." The framing below is the one I use when I am the engineer on the hook.
Three things drive how this behaves in production: the Azure SQL service tier you are on, the region your database lives in, and the identity model your application uses. Skip any of them and you will get surprising results.
Service tiers and what changes
Azure SQL ships in four major tiers: General Purpose, Business Critical, Hyperscale (Database), and the Managed Instance equivalents. Each tier has different memory budgets, different storage backends, different replica topologies. A feature that works the same way across tiers in the docs may behave differently under load because of those underlying differences.
-- Check the current tier and SKU of an Azure SQL database
SELECT
DATABASEPROPERTYEX(DB_NAME(), 'ServiceObjective') AS sku,
DATABASEPROPERTYEX(DB_NAME(), 'Edition') AS tier,
DATABASEPROPERTYEX(DB_NAME(), 'MaxSizeInBytes') / (1024.0 * 1024 * 1024) AS max_gb;
Run that on the database you are about to change before you change anything. The output tells you which docs page actually applies. Hyperscale features in particular do not apply to General Purpose, and vice versa.
Authentication options that work
You have four practical auth modes on Azure SQL. SQL authentication (username + password). Microsoft Entra password. Microsoft Entra integrated. Microsoft Entra managed identity. For anything that ships to production, managed identity is the right answer. Passwords leak. Managed identity does not.
-- Add an Entra service principal as an Azure SQL contained user
CREATE USER [my-app-prod] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datareader ADD MEMBER [my-app-prod];
ALTER ROLE db_datawriter ADD MEMBER [my-app-prod];
If you are calling from App Service, Functions, or Container Apps, enable managed identity on the caller, run the two lines above against your database, and you are done. No keys, no rotation, no leaked secrets in App Configuration.
Regions and data residency
Azure SQL runs in 60+ regions. For Indian regulated workloads — banks under the RBI IT framework, NBFCs under the NBFC framework, healthcare under the relevant DISHA guidelines, pin to Central India or South India. Cross-region geo-replication for DR can stay within India (Central India ⇄ South India) and stays compliant.
How to apply this in practice
- Confirm the SKU and tier of the database you are about to change.
SELECT DATABASEPROPERTYEX(DB_NAME(), 'ServiceObjective')is the quickest path. The applicable docs and behaviour vary by tier. - Run the change in a dev or staging database first. Capture the before-state with
sys.dm_db_index_usage_statsor whatever DMV is relevant to the change. Apply the change. Capture the after-state. Compare. - For any production-bound change, raise a CAB record (or whatever your team's change process calls it). Include the exact T-SQL or Azure CLI commands, the rollback steps, and the verification queries.
- Apply during a low-traffic window. Most Indian SaaS workloads have a window between 02:00 and 05:00 IST when traffic is at 10-20% of peak. That is your change window.
- Wire up Azure Monitor diagnostic settings if you have not already. Send
SQLInsights,AutomaticTuning, andQueryStoreRuntimeStatisticsto a Log Analytics workspace. One alert: 5xx response rate over 2% for 5 minutes. That alert has saved me twice this year. - Run a smoke test after the change. Run a representative query, time it, compare against a baseline you captured before. Sign off only if the numbers match what you expected.
I have seen teams skip step 5. the smoke test, every time there is schedule pressure. Skipping it costs more than the smoke test does, every single time. Twenty minutes of validation. Pays back the first time something silently regresses.
Caveats and what to double-check
- Some Azure SQL features are in preview. Preview features do not carry the standard 99.99% SLA. Read the small print on the feature's Microsoft Learn page before depending on it for production.
- Quota limits are per server, per region. The default DTU / vCore quota per subscription is generous but not unlimited. If you are provisioning at scale, raise a quota request three weeks before you need it. Microsoft support runs on its own clock.
- Regional availability differs. A feature in East US in October may not reach Central India until March. Confirm availability for your tenant region before designing around it.
- Long-term retention (LTR) backups have a separate billing line. Easy to miss. I have seen customers billed ₹40,000 a month for orphaned LTR backups whose source databases were deleted.
- The Azure portal UI lags the REST API by 4-6 weeks. If something works in the API but the portal cannot show it, that is normal. Trust the REST response.
Related work in your environment
- Document this configuration in your runbook with the exact database name, server, tier, and region. Future-you will thank present-you when the on-call page lands at 3 AM.
- Add a Microsoft Learn RSS subscription on the source doc page. When Microsoft updates the canonical version, you want to be notified rather than discovering it through a customer ticket.
- Run a quarterly review of every Azure SQL resource in your subscription.
az sql server list -o tableandaz sql db list --server <name> -o tabletake 10 seconds combined and surface every database. Kill the ones nobody uses: they leak budget. - Mirror your Azure SQL configuration in Bicep or Terraform. Resource drift is the silent killer of multi-region deployments and you will lose hours chasing differences between dev, staging, and prod that nobody can explain.
- For Indian regulated workloads, confirm with your DPO that your region choice, encryption posture, and audit configuration satisfy the RBI / NBFC / DISHA framework that applies. Document the mapping for your next audit.
Troubleshooting the failures I keep seeing
Three failure modes account for most of the Azure SQL incidents I have triaged in the last year. Knowing them in advance saves hours.
Login failed for the managed identity
You enabled managed identity on the caller. You ran CREATE USER FROM EXTERNAL PROVIDER on the database. The first call still fails with "Login failed for user '<token-identified principal>'". The cause is usually one of three: the managed identity name has a typo, the database does not have the contained user role assignment, or the token cache on the caller is stale and the next request will succeed.
-- Verify the Entra user exists on the database
SELECT name, type_desc, principal_id
FROM sys.database_principals
WHERE type IN ('E', 'X');
If the user appears in that result, the issue is on the caller side. Restart the App Service or Function. Tokens cache for an hour and a recently revoked token will fail until cache expiry.
Transient connection failures under load
Azure SQL throws transient errors, error numbers 4060, 40197, 40501, 40613, 49918, 49919, 49920. when the service is throttling, failing over, or load-balancing. Your code must catch these specifically and retry with exponential backoff. The .NET SqlClient v3+ does this automatically if you set ConnectRetryCount=3 and ConnectRetryInterval=10 in the connection string. The Python pyodbc driver does not, you write the retry loop yourself.
# Python pattern that handles Azure SQL transients
import pyodbc, time
TRANSIENT = {4060, 40197, 40501, 40613, 49918, 49919, 49920}
def query_with_retry(conn_str, sql, max_retries=5):
for attempt in range(max_retries):
try:
with pyodbc.connect(conn_str) as cn:
return cn.execute(sql).fetchall()
except pyodbc.OperationalError as e:
code = int(str(e).split('(')[1].split(',')[0]) if '(' in str(e) else 0
if code in TRANSIENT and attempt < max_retries - 1:
time.sleep(2 ** attempt)
continue
raise
Query suddenly slow after maintenance window
Azure SQL applies platform maintenance during your configured window. Sometimes that maintenance includes a server move, which clears the plan cache. The first request after the move recompiles every query: for a busy OLTP workload that is a brief spike in CPU and a brief drop in throughput. If you see a consistent slowdown lasting longer than 60 seconds, check Query Store for plan regressions and force the prior good plan if needed.
Last month I had a Mumbai customer hit this exact issue after a Saturday-night maintenance window. The fix was identifying the regressed plan in Query Store and forcing the prior plan with sp_query_store_force_plan. Total time to recover: 12 minutes.
Cost notes
Azure SQL pricing has three big levers. The compute tier (DTU or vCore), the storage allocation, and the redundancy choice. The compute tier dominates spend for almost every workload. Storage is small. Redundancy adds 25-100% depending on whether you pick local-redundant, zone-redundant, or geo-redundant.
A typical mid-market production database, General Purpose vCore-4, 100 GB storage, zone-redundant. runs about ₹65,000 per month at pay-as-you-go. With a 3-year reservation: about ₹38,000 per month. With Azure Hybrid Benefit applied on top: about ₹27,000 per month. The same database on the equivalent on-prem licence + hardware refresh: hard to compare cleanly because you have to factor depreciation, DBA cost, datacentre overhead.
For a Hyperscale database serving 8 million reads a day across two read replicas: about ₹1.4 lakh per month. The equivalent SQL Server Enterprise on-prem with two AG replicas plus DR site: roughly ₹2.1 lakh per month amortised over 5 years, plus DBA cost.
Rollback plan
If the change you just made is causing user-visible regressions, you have three rollback paths. Roll back the specific T-SQL change you applied (fastest, run the inverse statement). Restore the database to a point in time before the change (medium: minutes to hours depending on database size). Geo-failover to the secondary if your primary region is offline (slowest of the three but covers regional outages).
-- Point-in-time restore to 30 minutes before the change
az sql db restore \
--resource-group rg-prod-sql \
--server srv-prod-india \
--name mydb-restored \
--dest-name mydb-restored-pre-change \
--time "2026-06-04T14:30:00Z"
I always capture the exact UTC timestamp of the change in my CAB record. When rollback is on the table, those four characters of precision save twenty minutes of guessing. The restore creates a new database alongside the original, you then swap connection strings, or rename databases, depending on your cutover tolerance.
FAQ
References
- Microsoft Learn, official documentation for Azure SQL
- Microsoft tech community forums and Q&A
- Azure Service Health and Microsoft 365 Service health dashboards
- Azure pricing calculator (azure.microsoft.com/pricing/calculator)
Related fixes
Related guides worth a look while you sort this one out:
- Azure Policy Regulatory Compliance controls for Azure SQL Database & SQL Managed Instance
- Features comparison: Azure SQL Database and Azure SQL Managed Instance
- Features of SQL Database and SQL Managed Instance
- Blocked connectivity between SQL Managed Instance and Azure Key Vault or Azure Managed HSM
- Custom roles for SQL Server to Azure SQL Managed Instance migrations using ADS
- How does Azure Managed Instance secure my database