{"id":1385,"library":"azure-mgmt-sql","title":"Azure SQL Management Client Library","description":"The `azure-mgmt-sql` library is the Microsoft Azure SQL Management Client Library for Python. It provides classes and methods to programmatically manage Azure SQL resources such as SQL Servers, databases, elastic pools, firewalls, and more. It is part of the Azure SDK for Python (Track 2) and is currently at version 3.0.1. Azure SDK libraries typically follow a regular release cadence with updates corresponding to Azure service API changes.","status":"active","version":"3.0.1","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/sql/azure-mgmt-sql","tags":["azure","sql","management","cloud","microsoft"],"install":[{"cmd":"pip install azure-mgmt-sql azure-identity","lang":"bash","label":"Install core and authentication"}],"dependencies":[{"reason":"Core utilities and HTTP pipeline for Azure SDK.","package":"azure-core","optional":false},{"reason":"Recommended credential types for Azure authentication.","package":"azure-identity","optional":false},{"reason":"Common management plane utilities for Azure SDK.","package":"azure-mgmt-core","optional":false}],"imports":[{"note":"The client class is directly available under the top-level package.","wrong":"from azure.mgmt.sql.sql_management_client import SqlManagementClient","symbol":"SqlManagementClient","correct":"from azure.mgmt.sql import SqlManagementClient"},{"note":"Standard authentication credential for Azure SDK (Track 2).","symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"}],"quickstart":{"code":"import os\nfrom azure.identity import DefaultAzureCredential\nfrom azure.mgmt.sql import SqlManagementClient\n\n# Set your Azure Subscription ID in environment variables or replace directly\n# e.g., AZURE_SUBSCRIPTION_ID = 'your-subscription-id'\nsubscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID')\n\nif subscription_id == 'YOUR_SUBSCRIPTION_ID':\n    raise ValueError(\"Please set the AZURE_SUBSCRIPTION_ID environment variable or replace 'YOUR_SUBSCRIPTION_ID'\")\n\n# Authenticate using DefaultAzureCredential\n# This tries a series of authentication methods (environment variables, managed identity, VS Code, Azure CLI, etc.)\ncredential = DefaultAzureCredential()\n\n# Create a SQL Management Client\nsql_client = SqlManagementClient(credential, subscription_id)\n\nprint(f\"Listing SQL Servers in subscription '{subscription_id}':\")\n# List all SQL Servers in the subscription\ntry:\n    sql_servers = sql_client.servers.list()\n    for server in sql_servers:\n        print(f\"  - Server Name: {server.name}, Location: {server.location}\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential`, instantiate the `SqlManagementClient`, and then list all Azure SQL Servers within a specified subscription. Ensure `AZURE_SUBSCRIPTION_ID` is set in your environment variables for authentication."},"warnings":[{"fix":"Adopt `azure-identity` for authentication (e.g., `DefaultAzureCredential`). Client constructors now typically require a credential object and `subscription_id`. Method parameters and return types have been updated to be more consistent with the Azure REST API and Pythonic conventions. Consult the official Azure SDK documentation for the specific version.","message":"Migration from older Azure SDK (Track 1) clients to current (Track 2) clients involves significant breaking changes in client construction, authentication, and method signatures.","severity":"breaking","affected_versions":"Users migrating from `azure-mgmt-sql` versions prior to 2.0.0 or from older `msrestazure` based clients."},{"fix":"Always be mindful of the required scope for an operation. If an operation fails with a 'resource not found' or 'bad request' error, double-check if the resource group name is correctly provided and if the resource actually exists within that resource group.","message":"Many Azure SQL management operations are resource group-scoped. Operations like creating a server or database, or getting specific properties, require the resource group name in addition to the resource name.","severity":"gotcha","affected_versions":"All versions."},{"fix":"Decide whether you need synchronous or asynchronous operations for your application. If using `asyncio`, import and instantiate the `AsyncSqlManagementClient` and `await` its methods. For synchronous operations, use `SqlManagementClient` and do not use `await`.","message":"Azure SDK for Python offers both synchronous and asynchronous clients (e.g., `SqlManagementClient` vs `AsyncSqlManagementClient`). Mixing these can lead to runtime errors.","severity":"gotcha","affected_versions":"All versions."},{"fix":"Always iterate over the result of a list operation. For example, `for server in sql_client.servers.list():` or convert to a list explicitly if all results are needed upfront: `all_servers = list(sql_client.servers.list())`.","message":"List operations (e.g., `servers.list()`, `databases.list_by_server()`) return an iterable object (a 'pager') which needs to be iterated over to fetch all results, rather than a simple Python list.","severity":"gotcha","affected_versions":"All versions."}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}