Crea una nueva base de datos o actualiza una ya existente.
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}?api-version=2025-01-01
Parámetros de identificador URI
| Nombre |
En |
Requerido |
Tipo |
Description |
|
databaseName
|
path |
True
|
string
|
El nombre de la base de datos.
|
|
managedInstanceName
|
path |
True
|
string
|
Nombre de la instancia administrada.
|
|
resourceGroupName
|
path |
True
|
string
minLength: 1 maxLength: 90
|
Nombre del grupo de recursos. El nombre distingue mayúsculas de minúsculas.
|
|
subscriptionId
|
path |
True
|
string
(uuid)
|
Identificador de la suscripción de destino. El valor debe ser un UUID.
|
|
api-version
|
query |
True
|
string
minLength: 1
|
La versión de API que se va a utilizar para esta operación.
|
Cuerpo de la solicitud
| Nombre |
Requerido |
Tipo |
Description |
|
location
|
True
|
string
|
Ubicación geográfica donde reside el recurso
|
|
properties.autoCompleteRestore
|
|
boolean
|
Si se va a completar automáticamente la restauración de esta base de datos administrada.
|
|
properties.catalogCollation
|
|
CatalogCollationType
|
Intercalación del catálogo de metadatos.
|
|
properties.collation
|
|
string
|
Intercalación de la base de datos administrada.
|
|
properties.createMode
|
|
ManagedDatabaseCreateMode
|
Modo de creación de base de datos administrada. PointInTimeRestore: cree una base de datos restaurando una copia de seguridad a un momento dado de una base de datos existente. SourceDatabaseName, SourceManagedInstanceName y PointInTime deben especificarse. RestoreExternalBackup: cree una base de datos restaurando a partir de archivos de copia de seguridad externos. Se deben especificar intercalación, StorageContainerUri y StorageContainerSasToken. Recuperación: crea una base de datos restaurando una copia de seguridad con replicación geográfica. RecoverableDatabaseId debe especificarse como identificador de recurso de base de datos recuperable que se va a restaurar. RestoreLongTermRetentionBackup: cree una base de datos restaurando a partir de una copia de seguridad de retención a largo plazo (se requiere longTermRetentionBackupResourceId).
|
|
properties.crossSubscriptionRestorableDroppedDatabaseId
|
|
string
|
Identificador de recurso de base de datos que se puede restaurar entre suscripciones para restaurar al crear esta base de datos.
|
|
properties.crossSubscriptionSourceDatabaseId
|
|
string
|
Identificador de recursos de la base de datos de origen entre suscripciones asociada con la operación de creación de esta base de datos.
|
|
properties.crossSubscriptionTargetManagedInstanceId
|
|
string
|
Identificador de instancia administrada de destino que se usa en la restauración entre suscripciones.
|
|
properties.isLedgerOn
|
|
boolean
|
Si esta base de datos es una base de datos de libro de contabilidad, lo que significa que todas las tablas de la base de datos son tablas de libro de contabilidad. Nota: El valor de esta propiedad no se puede cambiar después de crear la base de datos.
|
|
properties.lastBackupName
|
|
string
|
Último nombre de archivo de copia de seguridad para la restauración de esta base de datos administrada.
|
|
properties.longTermRetentionBackupResourceId
|
|
string
|
Nombre de la copia de seguridad de retención a largo plazo que se va a usar para restaurar esta base de datos administrada.
|
|
properties.recoverableDatabaseId
|
|
string
|
Identificador de recurso de la base de datos recuperable asociada a la operación de creación de esta base de datos.
|
|
properties.restorableDroppedDatabaseId
|
|
string
|
Identificador de recurso de base de datos restaurable que se va a restaurar al crear esta base de datos.
|
|
properties.restorePointInTime
|
|
string
(date-time)
|
Conditional. Si createMode es PointInTimeRestore, se requiere este valor. Especifica el momento dado (ISO8601 formato) de la base de datos de origen que se restaurará para crear la nueva base de datos.
|
|
properties.sourceDatabaseId
|
|
string
|
Identificador de recurso de la base de datos de origen asociada a la operación de creación de esta base de datos.
|
|
properties.storageContainerIdentity
|
|
string
|
Conditional. Si createMode es RestoreExternalBackup, se usa este valor. Especifica la identidad usada para la autenticación del contenedor de almacenamiento. Puede ser "SharedAccessSignature" o "ManagedIdentity"; si no se especifica "SharedAccessSignature" se supone.
|
|
properties.storageContainerSasToken
|
|
string
|
Conditional. Si createMode es RestoreExternalBackup y storageContainerIdentity no es ManagedIdentity, se requiere este valor. Especifica el token sas del contenedor de almacenamiento.
|
|
properties.storageContainerUri
|
|
string
|
Conditional. Si createMode es RestoreExternalBackup, se requiere este valor. Especifica el URI del contenedor de almacenamiento donde se almacenan las copias de seguridad de esta restauración.
|
|
tags
|
|
object
|
Etiquetas de recursos.
|
Respuestas
| Nombre |
Tipo |
Description |
|
200 OK
|
ManagedDatabase
|
Operación de actualización 'ManagedDatabase' de recursos exitosa
|
|
201 Created
|
ManagedDatabase
|
Recurso 'ManagedDatabase' crear operación exitosa
Encabezados
- Location: string
- Retry-After: integer
|
|
202 Accepted
|
|
Operación de recursos aceptada.
Encabezados
- Location: string
- Retry-After: integer
|
|
Other Status Codes
|
ErrorResponse
|
Una respuesta de error inesperada.
|
Seguridad
azure_auth
Azure Active Directory OAuth2 Flow.
Tipo:
oauth2
Flujo:
implicit
Dirección URL de autorización:
https://login.microsoftonline.com/common/oauth2/authorize
Ámbitos
| Nombre |
Description |
|
user_impersonation
|
suplantar la cuenta de usuario
|
Ejemplos
Creates a new managed database by restoring from an external backup
Solicitud de ejemplo
PUT https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/managedInstance/databases/managedDatabase?api-version=2025-01-01
{
"location": "southeastasia",
"properties": {
"autoCompleteRestore": true,
"collation": "SQL_Latin1_General_CP1_CI_AS",
"createMode": "RestoreExternalBackup",
"lastBackupName": "last_backup_name",
"storageContainerSasToken": "sv=2015-12-11&sr=c&sp=rl&sig=1234",
"storageContainerUri": "https://myaccountname.blob.core.windows.net/backups"
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.sql import SqlManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-sql
# USAGE
python managed_database_create_restore_external_backup.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = SqlManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.managed_databases.begin_create_or_update(
resource_group_name="Default-SQL-SouthEastAsia",
managed_instance_name="managedInstance",
database_name="managedDatabase",
parameters={
"location": "southeastasia",
"properties": {
"autoCompleteRestore": True,
"collation": "SQL_Latin1_General_CP1_CI_AS",
"createMode": "RestoreExternalBackup",
"lastBackupName": "last_backup_name",
"storageContainerSasToken": "sv=2015-12-11&sr=c&sp=rl&sig=1234",
"storageContainerUri": "https://myaccountname.blob.core.windows.net/backups",
},
},
).result()
print(response)
# x-ms-original-file: 2025-01-01/ManagedDatabaseCreateRestoreExternalBackup.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Sql.Models;
using Azure.ResourceManager.Sql;
// Generated from example definition: specification/sql/resource-manager/Microsoft.Sql/SQL/stable/2025-01-01/examples/ManagedDatabaseCreateRestoreExternalBackup.json
// this example is just showing the usage of "ManagedDatabases_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://dotnet.territoriali.olinfo.it/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ManagedInstanceResource created on azure
// for more information of creating ManagedInstanceResource, please refer to the document of ManagedInstanceResource
string subscriptionId = "00000000-1111-2222-3333-444444444444";
string resourceGroupName = "Default-SQL-SouthEastAsia";
string managedInstanceName = "managedInstance";
ResourceIdentifier managedInstanceResourceId = ManagedInstanceResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, managedInstanceName);
ManagedInstanceResource managedInstance = client.GetManagedInstanceResource(managedInstanceResourceId);
// get the collection of this ManagedDatabaseResource
ManagedDatabaseCollection collection = managedInstance.GetManagedDatabases();
// invoke the operation
string databaseName = "managedDatabase";
ManagedDatabaseData data = new ManagedDatabaseData(new AzureLocation("southeastasia"))
{
Collation = "SQL_Latin1_General_CP1_CI_AS",
CreateMode = ManagedDatabaseCreateMode.RestoreExternalBackup,
StorageContainerUri = new Uri("https://myaccountname.blob.core.windows.net/backups"),
StorageContainerSasToken = "sv=2015-12-11&sr=c&sp=rl&sig=1234",
AllowAutoCompleteRestore = true,
LastBackupName = "last_backup_name",
};
ArmOperation<ManagedDatabaseResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, databaseName, data);
ManagedDatabaseResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
ManagedDatabaseData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Respuesta de muestra
{
"name": "testdb1",
"type": "Microsoft.Sql/managedInstances/databases",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr/databases/testdb1",
"location": "southeastasia",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"creationDate": "2017-06-07T04:41:33.937Z",
"defaultSecondaryLocation": "North Europe",
"isLedgerOn": false,
"status": "Online"
},
"tags": {
"tagKey1": "TagValue1"
}
}
{
"name": "testdb2",
"type": "Microsoft.Sql/managedInstances/databases",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr/databases/testdb2",
"location": "southeastasia",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"creationDate": "2017-06-07T04:41:33.937Z",
"defaultSecondaryLocation": "North Europe",
"isLedgerOn": false,
"status": "Online"
},
"tags": {
"tagKey1": "TagValue1"
}
}
Creates a new managed database by restoring from an external backup using managed identity
Solicitud de ejemplo
PUT https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/managedInstance/databases/managedDatabase?api-version=2025-01-01
{
"location": "southeastasia",
"properties": {
"autoCompleteRestore": true,
"collation": "SQL_Latin1_General_CP1_CI_AS",
"createMode": "RestoreExternalBackup",
"lastBackupName": "last_backup_name",
"storageContainerIdentity": "ManagedIdentity",
"storageContainerUri": "https://myaccountname.blob.core.windows.net/backups"
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.sql import SqlManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-sql
# USAGE
python managed_database_create_restore_external_backup_managed_identity.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = SqlManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.managed_databases.begin_create_or_update(
resource_group_name="Default-SQL-SouthEastAsia",
managed_instance_name="managedInstance",
database_name="managedDatabase",
parameters={
"location": "southeastasia",
"properties": {
"autoCompleteRestore": True,
"collation": "SQL_Latin1_General_CP1_CI_AS",
"createMode": "RestoreExternalBackup",
"lastBackupName": "last_backup_name",
"storageContainerIdentity": "ManagedIdentity",
"storageContainerUri": "https://myaccountname.blob.core.windows.net/backups",
},
},
).result()
print(response)
# x-ms-original-file: 2025-01-01/ManagedDatabaseCreateRestoreExternalBackupManagedIdentity.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Sql.Models;
using Azure.ResourceManager.Sql;
// Generated from example definition: specification/sql/resource-manager/Microsoft.Sql/SQL/stable/2025-01-01/examples/ManagedDatabaseCreateRestoreExternalBackupManagedIdentity.json
// this example is just showing the usage of "ManagedDatabases_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://dotnet.territoriali.olinfo.it/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ManagedInstanceResource created on azure
// for more information of creating ManagedInstanceResource, please refer to the document of ManagedInstanceResource
string subscriptionId = "00000000-1111-2222-3333-444444444444";
string resourceGroupName = "Default-SQL-SouthEastAsia";
string managedInstanceName = "managedInstance";
ResourceIdentifier managedInstanceResourceId = ManagedInstanceResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, managedInstanceName);
ManagedInstanceResource managedInstance = client.GetManagedInstanceResource(managedInstanceResourceId);
// get the collection of this ManagedDatabaseResource
ManagedDatabaseCollection collection = managedInstance.GetManagedDatabases();
// invoke the operation
string databaseName = "managedDatabase";
ManagedDatabaseData data = new ManagedDatabaseData(new AzureLocation("southeastasia"))
{
Collation = "SQL_Latin1_General_CP1_CI_AS",
CreateMode = ManagedDatabaseCreateMode.RestoreExternalBackup,
StorageContainerUri = new Uri("https://myaccountname.blob.core.windows.net/backups"),
StorageContainerIdentity = "ManagedIdentity",
AllowAutoCompleteRestore = true,
LastBackupName = "last_backup_name",
};
ArmOperation<ManagedDatabaseResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, databaseName, data);
ManagedDatabaseResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
ManagedDatabaseData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Respuesta de muestra
{
"name": "testdb1",
"type": "Microsoft.Sql/managedInstances/databases",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr/databases/testdb1",
"location": "southeastasia",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"creationDate": "2017-06-07T04:41:33.937Z",
"defaultSecondaryLocation": "North Europe",
"isLedgerOn": false,
"status": "Online"
},
"tags": {
"tagKey1": "TagValue1"
}
}
{
"name": "testdb2",
"type": "Microsoft.Sql/managedInstances/databases",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr/databases/testdb2",
"location": "southeastasia",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"creationDate": "2017-06-07T04:41:33.937Z",
"defaultSecondaryLocation": "North Europe",
"isLedgerOn": false,
"status": "Online"
},
"tags": {
"tagKey1": "TagValue1"
}
}
Creates a new managed database from restoring a geo-replicated backup
Solicitud de ejemplo
PUT https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/server1/databases/testdb_recovered?api-version=2025-01-01
{
"location": "southeastasia",
"properties": {
"createMode": "Recovery",
"recoverableDatabaseId": "/subscriptions/11111111-2222-3333-4444-555555555555/resourceGroups/Default-SQL-WestEurope/providers/Microsoft.Sql/managedInstances/testsvr/recoverableDatabases/testdb"
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.sql import SqlManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-sql
# USAGE
python managed_database_create_recovery.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = SqlManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.managed_databases.begin_create_or_update(
resource_group_name="Default-SQL-SouthEastAsia",
managed_instance_name="server1",
database_name="testdb_recovered",
parameters={
"location": "southeastasia",
"properties": {
"createMode": "Recovery",
"recoverableDatabaseId": "/subscriptions/11111111-2222-3333-4444-555555555555/resourceGroups/Default-SQL-WestEurope/providers/Microsoft.Sql/managedInstances/testsvr/recoverableDatabases/testdb",
},
},
).result()
print(response)
# x-ms-original-file: 2025-01-01/ManagedDatabaseCreateRecovery.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Sql.Models;
using Azure.ResourceManager.Sql;
// Generated from example definition: specification/sql/resource-manager/Microsoft.Sql/SQL/stable/2025-01-01/examples/ManagedDatabaseCreateRecovery.json
// this example is just showing the usage of "ManagedDatabases_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://dotnet.territoriali.olinfo.it/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ManagedInstanceResource created on azure
// for more information of creating ManagedInstanceResource, please refer to the document of ManagedInstanceResource
string subscriptionId = "00000000-1111-2222-3333-444444444444";
string resourceGroupName = "Default-SQL-SouthEastAsia";
string managedInstanceName = "server1";
ResourceIdentifier managedInstanceResourceId = ManagedInstanceResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, managedInstanceName);
ManagedInstanceResource managedInstance = client.GetManagedInstanceResource(managedInstanceResourceId);
// get the collection of this ManagedDatabaseResource
ManagedDatabaseCollection collection = managedInstance.GetManagedDatabases();
// invoke the operation
string databaseName = "testdb_recovered";
ManagedDatabaseData data = new ManagedDatabaseData(new AzureLocation("southeastasia"))
{
CreateMode = ManagedDatabaseCreateMode.Recovery,
RecoverableDatabaseId = new ResourceIdentifier("/subscriptions/11111111-2222-3333-4444-555555555555/resourceGroups/Default-SQL-WestEurope/providers/Microsoft.Sql/managedInstances/testsvr/recoverableDatabases/testdb"),
};
ArmOperation<ManagedDatabaseResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, databaseName, data);
ManagedDatabaseResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
ManagedDatabaseData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Respuesta de muestra
{
"name": "testdb_recovered",
"type": "Microsoft.Sql/managedInstances/databases",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/server1/recoverableDatabases/testdb_recovered",
"location": "southeastasia",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"creationDate": "2018-11-07T04:41:33.937Z",
"isLedgerOn": false,
"status": "Online"
},
"tags": {
"tagKey1": "TagValue1"
}
}
{
"name": "testdb_recovered",
"type": "Microsoft.Sql/managedInstances/databases",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr/recoverableDatabases/testdb_recovered",
"location": "southeastasia",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"creationDate": "2018-11-07T04:41:33.937Z",
"isLedgerOn": false,
"status": "Online"
},
"tags": {
"tagKey1": "TagValue1"
}
}
Creates a new managed database from restoring a long term retention backup
Solicitud de ejemplo
PUT https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/managedInstance/databases/managedDatabase?api-version=2025-01-01
{
"location": "southeastasia",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"createMode": "RestoreExternalBackup",
"storageContainerSasToken": "sv=2015-12-11&sr=c&sp=rl&sig=1234",
"storageContainerUri": "https://myaccountname.blob.core.windows.net/backups"
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.sql import SqlManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-sql
# USAGE
python managed_database_create_restore_ltr_backup.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = SqlManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.managed_databases.begin_create_or_update(
resource_group_name="Default-SQL-SouthEastAsia",
managed_instance_name="managedInstance",
database_name="managedDatabase",
parameters={
"location": "southeastasia",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"createMode": "RestoreExternalBackup",
"storageContainerSasToken": "sv=2015-12-11&sr=c&sp=rl&sig=1234",
"storageContainerUri": "https://myaccountname.blob.core.windows.net/backups",
},
},
).result()
print(response)
# x-ms-original-file: 2025-01-01/ManagedDatabaseCreateRestoreLtrBackup.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Sql.Models;
using Azure.ResourceManager.Sql;
// Generated from example definition: specification/sql/resource-manager/Microsoft.Sql/SQL/stable/2025-01-01/examples/ManagedDatabaseCreateRestoreLtrBackup.json
// this example is just showing the usage of "ManagedDatabases_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://dotnet.territoriali.olinfo.it/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ManagedInstanceResource created on azure
// for more information of creating ManagedInstanceResource, please refer to the document of ManagedInstanceResource
string subscriptionId = "00000000-1111-2222-3333-444444444444";
string resourceGroupName = "Default-SQL-SouthEastAsia";
string managedInstanceName = "managedInstance";
ResourceIdentifier managedInstanceResourceId = ManagedInstanceResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, managedInstanceName);
ManagedInstanceResource managedInstance = client.GetManagedInstanceResource(managedInstanceResourceId);
// get the collection of this ManagedDatabaseResource
ManagedDatabaseCollection collection = managedInstance.GetManagedDatabases();
// invoke the operation
string databaseName = "managedDatabase";
ManagedDatabaseData data = new ManagedDatabaseData(new AzureLocation("southeastasia"))
{
Collation = "SQL_Latin1_General_CP1_CI_AS",
CreateMode = ManagedDatabaseCreateMode.RestoreExternalBackup,
StorageContainerUri = new Uri("https://myaccountname.blob.core.windows.net/backups"),
StorageContainerSasToken = "sv=2015-12-11&sr=c&sp=rl&sig=1234",
};
ArmOperation<ManagedDatabaseResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, databaseName, data);
ManagedDatabaseResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
ManagedDatabaseData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Respuesta de muestra
{
"name": "testdb1",
"type": "Microsoft.Sql/managedInstances/databases",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr/databases/testdb1",
"location": "southeastasia",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"creationDate": "2017-06-07T04:41:33.937Z",
"defaultSecondaryLocation": "North Europe",
"isLedgerOn": false,
"status": "Online"
},
"tags": {
"tagKey1": "TagValue1"
}
}
{
"name": "testdb2",
"type": "Microsoft.Sql/managedInstances/databases",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr/databases/testdb2",
"location": "southeastasia",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"creationDate": "2017-06-07T04:41:33.937Z",
"defaultSecondaryLocation": "North Europe",
"isLedgerOn": false,
"status": "Online"
},
"tags": {
"tagKey1": "TagValue1"
}
}
Creates a new managed database using cross subscription point in time restore
Solicitud de ejemplo
PUT https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/managedInstance/databases/managedDatabase?api-version=2025-01-01
{
"location": "southeastasia",
"properties": {
"createMode": "PointInTimeRestore",
"crossSubscriptionSourceDatabaseId": "/subscriptions/11111111-2222-3333-4444-555555555555/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr2/databases/testdb",
"crossSubscriptionTargetManagedInstanceId": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr",
"restorePointInTime": "2017-07-14T05:35:31.503Z"
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.sql import SqlManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-sql
# USAGE
python managed_database_create_cross_subscription_point_in_time_restore.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = SqlManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.managed_databases.begin_create_or_update(
resource_group_name="Default-SQL-SouthEastAsia",
managed_instance_name="managedInstance",
database_name="managedDatabase",
parameters={
"location": "southeastasia",
"properties": {
"createMode": "PointInTimeRestore",
"crossSubscriptionSourceDatabaseId": "/subscriptions/11111111-2222-3333-4444-555555555555/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr2/databases/testdb",
"crossSubscriptionTargetManagedInstanceId": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr",
"restorePointInTime": "2017-07-14T05:35:31.503Z",
},
},
).result()
print(response)
# x-ms-original-file: 2025-01-01/ManagedDatabaseCreateCrossSubscriptionPointInTimeRestore.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Sql.Models;
using Azure.ResourceManager.Sql;
// Generated from example definition: specification/sql/resource-manager/Microsoft.Sql/SQL/stable/2025-01-01/examples/ManagedDatabaseCreateCrossSubscriptionPointInTimeRestore.json
// this example is just showing the usage of "ManagedDatabases_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://dotnet.territoriali.olinfo.it/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ManagedInstanceResource created on azure
// for more information of creating ManagedInstanceResource, please refer to the document of ManagedInstanceResource
string subscriptionId = "00000000-1111-2222-3333-444444444444";
string resourceGroupName = "Default-SQL-SouthEastAsia";
string managedInstanceName = "managedInstance";
ResourceIdentifier managedInstanceResourceId = ManagedInstanceResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, managedInstanceName);
ManagedInstanceResource managedInstance = client.GetManagedInstanceResource(managedInstanceResourceId);
// get the collection of this ManagedDatabaseResource
ManagedDatabaseCollection collection = managedInstance.GetManagedDatabases();
// invoke the operation
string databaseName = "managedDatabase";
ManagedDatabaseData data = new ManagedDatabaseData(new AzureLocation("southeastasia"))
{
RestorePointInTime = DateTimeOffset.Parse("2017-07-14T05:35:31.503Z"),
CreateMode = ManagedDatabaseCreateMode.PointInTimeRestore,
CrossSubscriptionSourceDatabaseId = new ResourceIdentifier("/subscriptions/11111111-2222-3333-4444-555555555555/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr2/databases/testdb"),
CrossSubscriptionTargetManagedInstanceId = new ResourceIdentifier("/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr"),
};
ArmOperation<ManagedDatabaseResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, databaseName, data);
ManagedDatabaseResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
ManagedDatabaseData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Respuesta de muestra
{
"name": "testdb1",
"type": "Microsoft.Sql/managedInstances/databases",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr/databases/testdb1",
"location": "southeastasia",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"creationDate": "2017-06-07T04:41:33.937Z",
"defaultSecondaryLocation": "North Europe",
"isLedgerOn": false,
"status": "Online"
},
"tags": {
"tagKey1": "TagValue1"
}
}
{
"name": "testdb2",
"type": "Microsoft.Sql/managedInstances/databases",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr/databases/testdb2",
"location": "southeastasia",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"creationDate": "2017-06-07T04:41:33.937Z",
"defaultSecondaryLocation": "North Europe",
"isLedgerOn": false,
"status": "Online"
},
"tags": {
"tagKey1": "TagValue1"
}
}
Creates a new managed database using point in time restore
Solicitud de ejemplo
PUT https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/managedInstance/databases/managedDatabase?api-version=2025-01-01
{
"location": "southeastasia",
"properties": {
"createMode": "PointInTimeRestore",
"restorePointInTime": "2017-07-14T05:35:31.503Z",
"sourceDatabaseId": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr/databases/testdb"
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.sql import SqlManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-sql
# USAGE
python managed_database_create_point_in_time_restore.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = SqlManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.managed_databases.begin_create_or_update(
resource_group_name="Default-SQL-SouthEastAsia",
managed_instance_name="managedInstance",
database_name="managedDatabase",
parameters={
"location": "southeastasia",
"properties": {
"createMode": "PointInTimeRestore",
"restorePointInTime": "2017-07-14T05:35:31.503Z",
"sourceDatabaseId": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr/databases/testdb",
},
},
).result()
print(response)
# x-ms-original-file: 2025-01-01/ManagedDatabaseCreatePointInTimeRestore.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Sql.Models;
using Azure.ResourceManager.Sql;
// Generated from example definition: specification/sql/resource-manager/Microsoft.Sql/SQL/stable/2025-01-01/examples/ManagedDatabaseCreatePointInTimeRestore.json
// this example is just showing the usage of "ManagedDatabases_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://dotnet.territoriali.olinfo.it/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ManagedInstanceResource created on azure
// for more information of creating ManagedInstanceResource, please refer to the document of ManagedInstanceResource
string subscriptionId = "00000000-1111-2222-3333-444444444444";
string resourceGroupName = "Default-SQL-SouthEastAsia";
string managedInstanceName = "managedInstance";
ResourceIdentifier managedInstanceResourceId = ManagedInstanceResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, managedInstanceName);
ManagedInstanceResource managedInstance = client.GetManagedInstanceResource(managedInstanceResourceId);
// get the collection of this ManagedDatabaseResource
ManagedDatabaseCollection collection = managedInstance.GetManagedDatabases();
// invoke the operation
string databaseName = "managedDatabase";
ManagedDatabaseData data = new ManagedDatabaseData(new AzureLocation("southeastasia"))
{
RestorePointInTime = DateTimeOffset.Parse("2017-07-14T05:35:31.503Z"),
CreateMode = ManagedDatabaseCreateMode.PointInTimeRestore,
SourceDatabaseId = new ResourceIdentifier("/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr/databases/testdb"),
};
ArmOperation<ManagedDatabaseResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, databaseName, data);
ManagedDatabaseResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
ManagedDatabaseData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Respuesta de muestra
{
"name": "testdb1",
"type": "Microsoft.Sql/managedInstances/databases",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr/databases/testdb1",
"location": "southeastasia",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"creationDate": "2017-06-07T04:41:33.937Z",
"defaultSecondaryLocation": "North Europe",
"isLedgerOn": false,
"status": "Online"
},
"tags": {
"tagKey1": "TagValue1"
}
}
{
"name": "testdb2",
"type": "Microsoft.Sql/managedInstances/databases",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr/databases/testdb2",
"location": "southeastasia",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"creationDate": "2017-06-07T04:41:33.937Z",
"defaultSecondaryLocation": "North Europe",
"isLedgerOn": false,
"status": "Online"
},
"tags": {
"tagKey1": "TagValue1"
}
}
Creates a new managed database with ledger on.
Solicitud de ejemplo
PUT https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/managedInstance/databases/managedDatabase?api-version=2025-01-01
{
"location": "southeastasia",
"properties": {
"isLedgerOn": true
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.sql import SqlManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-sql
# USAGE
python create_managed_database_ledger.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = SqlManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.managed_databases.begin_create_or_update(
resource_group_name="Default-SQL-SouthEastAsia",
managed_instance_name="managedInstance",
database_name="managedDatabase",
parameters={"location": "southeastasia", "properties": {"isLedgerOn": True}},
).result()
print(response)
# x-ms-original-file: 2025-01-01/CreateManagedDatabaseLedger.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Sql.Models;
using Azure.ResourceManager.Sql;
// Generated from example definition: specification/sql/resource-manager/Microsoft.Sql/SQL/stable/2025-01-01/examples/CreateManagedDatabaseLedger.json
// this example is just showing the usage of "ManagedDatabases_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://dotnet.territoriali.olinfo.it/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ManagedInstanceResource created on azure
// for more information of creating ManagedInstanceResource, please refer to the document of ManagedInstanceResource
string subscriptionId = "00000000-1111-2222-3333-444444444444";
string resourceGroupName = "Default-SQL-SouthEastAsia";
string managedInstanceName = "managedInstance";
ResourceIdentifier managedInstanceResourceId = ManagedInstanceResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, managedInstanceName);
ManagedInstanceResource managedInstance = client.GetManagedInstanceResource(managedInstanceResourceId);
// get the collection of this ManagedDatabaseResource
ManagedDatabaseCollection collection = managedInstance.GetManagedDatabases();
// invoke the operation
string databaseName = "managedDatabase";
ManagedDatabaseData data = new ManagedDatabaseData(new AzureLocation("southeastasia"))
{
IsLedgerOn = true,
};
ArmOperation<ManagedDatabaseResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, databaseName, data);
ManagedDatabaseResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
ManagedDatabaseData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Respuesta de muestra
{
"name": "testdb1",
"type": "Microsoft.Sql/managedInstances/databases",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testcl/databases/testdb1",
"location": "southeastasia",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"creationDate": "2017-06-07T04:41:33.937Z",
"defaultSecondaryLocation": "North Europe",
"isLedgerOn": true,
"status": "Online"
},
"tags": {
"tagKey1": "TagValue1"
}
}
{
"name": "testdb2",
"type": "Microsoft.Sql/managedInstances/databases",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testcl/databases/testdb2",
"location": "southeastasia",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"creationDate": "2017-06-07T04:41:33.937Z",
"defaultSecondaryLocation": "North Europe",
"isLedgerOn": true,
"status": "Online"
},
"tags": {
"tagKey1": "TagValue1"
}
}
Location: https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/locations/southeastasia/operationStatus/default/operationId/00000000-0000-0000-0000-000000000000?api-version=2022-08-01
Creates a new managed database with maximal properties
Solicitud de ejemplo
PUT https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/managedInstance/databases/managedDatabase?api-version=2025-01-01
{
"location": "southeastasia",
"tags": {
"tagKey1": "TagValue1"
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.sql import SqlManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-sql
# USAGE
python managed_database_create_max.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = SqlManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.managed_databases.begin_create_or_update(
resource_group_name="Default-SQL-SouthEastAsia",
managed_instance_name="managedInstance",
database_name="managedDatabase",
parameters={"location": "southeastasia", "tags": {"tagKey1": "TagValue1"}},
).result()
print(response)
# x-ms-original-file: 2025-01-01/ManagedDatabaseCreateMax.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Sql.Models;
using Azure.ResourceManager.Sql;
// Generated from example definition: specification/sql/resource-manager/Microsoft.Sql/SQL/stable/2025-01-01/examples/ManagedDatabaseCreateMax.json
// this example is just showing the usage of "ManagedDatabases_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://dotnet.territoriali.olinfo.it/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ManagedInstanceResource created on azure
// for more information of creating ManagedInstanceResource, please refer to the document of ManagedInstanceResource
string subscriptionId = "00000000-1111-2222-3333-444444444444";
string resourceGroupName = "Default-SQL-SouthEastAsia";
string managedInstanceName = "managedInstance";
ResourceIdentifier managedInstanceResourceId = ManagedInstanceResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, managedInstanceName);
ManagedInstanceResource managedInstance = client.GetManagedInstanceResource(managedInstanceResourceId);
// get the collection of this ManagedDatabaseResource
ManagedDatabaseCollection collection = managedInstance.GetManagedDatabases();
// invoke the operation
string databaseName = "managedDatabase";
ManagedDatabaseData data = new ManagedDatabaseData(new AzureLocation("southeastasia"))
{
Tags =
{
["tagKey1"] = "TagValue1"
},
};
ArmOperation<ManagedDatabaseResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, databaseName, data);
ManagedDatabaseResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
ManagedDatabaseData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Respuesta de muestra
{
"name": "testdb1",
"type": "Microsoft.Sql/managedInstances/databases",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr/databases/testdb1",
"location": "southeastasia",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"creationDate": "2017-06-07T04:41:33.937Z",
"defaultSecondaryLocation": "North Europe",
"isLedgerOn": false,
"status": "Online"
},
"tags": {
"tagKey1": "TagValue1"
}
}
{
"name": "testdb2",
"type": "Microsoft.Sql/managedInstances/databases",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr/databases/testdb2",
"location": "southeastasia",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"creationDate": "2017-06-07T04:41:33.937Z",
"defaultSecondaryLocation": "North Europe",
"isLedgerOn": false,
"status": "Online"
},
"tags": {
"tagKey1": "TagValue1"
}
}
Location: https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/locations/southeastasia/operationStatus/default/operationId/00000000-0000-0000-0000-000000000000?api-version=2017-03-01
Creates a new managed database with minimal properties
Solicitud de ejemplo
PUT https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/managedInstance/databases/managedDatabase?api-version=2025-01-01
{
"location": "southeastasia"
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.sql import SqlManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-sql
# USAGE
python managed_database_create_min.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = SqlManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.managed_databases.begin_create_or_update(
resource_group_name="Default-SQL-SouthEastAsia",
managed_instance_name="managedInstance",
database_name="managedDatabase",
parameters={"location": "southeastasia"},
).result()
print(response)
# x-ms-original-file: 2025-01-01/ManagedDatabaseCreateMin.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Sql.Models;
using Azure.ResourceManager.Sql;
// Generated from example definition: specification/sql/resource-manager/Microsoft.Sql/SQL/stable/2025-01-01/examples/ManagedDatabaseCreateMin.json
// this example is just showing the usage of "ManagedDatabases_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://dotnet.territoriali.olinfo.it/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ManagedInstanceResource created on azure
// for more information of creating ManagedInstanceResource, please refer to the document of ManagedInstanceResource
string subscriptionId = "00000000-1111-2222-3333-444444444444";
string resourceGroupName = "Default-SQL-SouthEastAsia";
string managedInstanceName = "managedInstance";
ResourceIdentifier managedInstanceResourceId = ManagedInstanceResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, managedInstanceName);
ManagedInstanceResource managedInstance = client.GetManagedInstanceResource(managedInstanceResourceId);
// get the collection of this ManagedDatabaseResource
ManagedDatabaseCollection collection = managedInstance.GetManagedDatabases();
// invoke the operation
string databaseName = "managedDatabase";
ManagedDatabaseData data = new ManagedDatabaseData(new AzureLocation("southeastasia"));
ArmOperation<ManagedDatabaseResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, databaseName, data);
ManagedDatabaseResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
ManagedDatabaseData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Respuesta de muestra
{
"name": "testdb1",
"type": "Microsoft.Sql/managedInstances/databases",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr/databases/testdb1",
"location": "southeastasia",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"creationDate": "2017-06-07T04:41:33.937Z",
"defaultSecondaryLocation": "North Europe",
"isLedgerOn": false,
"status": "Online"
}
}
{
"name": "testdb2",
"type": "Microsoft.Sql/managedInstances/databases",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/managedInstances/testsvr/databases/testdb2",
"location": "southeastasia",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"creationDate": "2017-06-07T04:41:33.937Z",
"defaultSecondaryLocation": "North Europe",
"isLedgerOn": false,
"status": "Online"
}
}
Location: https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/locations/southeastasia/operationStatus/default/operationId/00000000-0000-0000-0000-000000000000?api-version=2017-03-01
Definiciones
| Nombre |
Description |
|
CatalogCollationType
|
Intercalación del catálogo de metadatos.
|
|
createdByType
|
Tipo de identidad que creó el recurso.
|
|
ErrorAdditionalInfo
|
Información adicional sobre el error de administración de recursos.
|
|
ErrorDetail
|
Detalle del error.
|
|
ErrorResponse
|
Respuesta de error
|
|
InaccessibilityReason
|
Tipo de causa raíz. Los valores permitidos son "TransparentDataEncryption", "DatabaseReplication" y "Unknown".
|
|
ManagedDatabase
|
Un recurso de base de datos administrado.
|
|
ManagedDatabaseCreateMode
|
Modo de creación de base de datos administrada. PointInTimeRestore: cree una base de datos restaurando una copia de seguridad a un momento dado de una base de datos existente. SourceDatabaseName, SourceManagedInstanceName y PointInTime deben especificarse. RestoreExternalBackup: cree una base de datos restaurando a partir de archivos de copia de seguridad externos. Se deben especificar intercalación, StorageContainerUri y StorageContainerSasToken. Recuperación: crea una base de datos restaurando una copia de seguridad con replicación geográfica. RecoverableDatabaseId debe especificarse como identificador de recurso de base de datos recuperable que se va a restaurar. RestoreLongTermRetentionBackup: cree una base de datos restaurando a partir de una copia de seguridad de retención a largo plazo (se requiere longTermRetentionBackupResourceId).
|
|
ManagedDatabaseExtendedAccessibilityInfo
|
Información de accesibilidad extendida de la base de datos administrada
|
|
ManagedDatabaseStatus
|
Estado de la base de datos.
|
|
systemData
|
Metadatos relativos a la creación y última modificación del recurso.
|
CatalogCollationType
Enumeración
Intercalación del catálogo de metadatos.
| Valor |
Description |
|
DATABASE_DEFAULT
|
DATABASE_DEFAULT
|
|
SQL_Latin1_General_CP1_CI_AS
|
SQL_Latin1_General_CP1_CI_AS
|
createdByType
Enumeración
Tipo de identidad que creó el recurso.
| Valor |
Description |
|
User
|
|
|
Application
|
|
|
ManagedIdentity
|
|
|
Key
|
|
ErrorAdditionalInfo
Objeto
Información adicional sobre el error de administración de recursos.
| Nombre |
Tipo |
Description |
|
info
|
object
|
Información adicional.
|
|
type
|
string
|
Tipo de información adicional.
|
ErrorDetail
Objeto
Detalle del error.
| Nombre |
Tipo |
Description |
|
additionalInfo
|
ErrorAdditionalInfo[]
|
Información adicional del error.
|
|
code
|
string
|
Código de error.
|
|
details
|
ErrorDetail[]
|
Detalles del error.
|
|
message
|
string
|
El mensaje de error.
|
|
target
|
string
|
Destino del error.
|
ErrorResponse
Objeto
Respuesta de error
| Nombre |
Tipo |
Description |
|
error
|
ErrorDetail
|
Objeto de error.
|
InaccessibilityReason
Enumeración
Tipo de causa raíz. Los valores permitidos son "TransparentDataEncryption", "DatabaseReplication" y "Unknown".
| Valor |
Description |
|
Unknown
|
Desconocido
|
|
TransparentDataEncryption
|
TransparentDataEncryption
|
|
DatabaseReplication
|
Replicación de bases de datos
|
ManagedDatabase
Objeto
Un recurso de base de datos administrado.
| Nombre |
Tipo |
Description |
|
id
|
string
(arm-id)
|
Identificador de recurso completo para el recurso. Por ejemplo, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}"
|
|
location
|
string
|
Ubicación geográfica donde reside el recurso
|
|
name
|
string
|
Nombre del recurso
|
|
properties.autoCompleteRestore
|
boolean
|
Si se va a completar automáticamente la restauración de esta base de datos administrada.
|
|
properties.catalogCollation
|
CatalogCollationType
|
Intercalación del catálogo de metadatos.
|
|
properties.collation
|
string
|
Intercalación de la base de datos administrada.
|
|
properties.createMode
|
ManagedDatabaseCreateMode
|
Modo de creación de base de datos administrada. PointInTimeRestore: cree una base de datos restaurando una copia de seguridad a un momento dado de una base de datos existente. SourceDatabaseName, SourceManagedInstanceName y PointInTime deben especificarse. RestoreExternalBackup: cree una base de datos restaurando a partir de archivos de copia de seguridad externos. Se deben especificar intercalación, StorageContainerUri y StorageContainerSasToken. Recuperación: crea una base de datos restaurando una copia de seguridad con replicación geográfica. RecoverableDatabaseId debe especificarse como identificador de recurso de base de datos recuperable que se va a restaurar. RestoreLongTermRetentionBackup: cree una base de datos restaurando a partir de una copia de seguridad de retención a largo plazo (se requiere longTermRetentionBackupResourceId).
|
|
properties.creationDate
|
string
(date-time)
|
Fecha de creación de la base de datos.
|
|
properties.crossSubscriptionRestorableDroppedDatabaseId
|
string
|
Identificador de recurso de base de datos que se puede restaurar entre suscripciones para restaurar al crear esta base de datos.
|
|
properties.crossSubscriptionSourceDatabaseId
|
string
|
Identificador de recursos de la base de datos de origen entre suscripciones asociada con la operación de creación de esta base de datos.
|
|
properties.crossSubscriptionTargetManagedInstanceId
|
string
|
Identificador de instancia administrada de destino que se usa en la restauración entre suscripciones.
|
|
properties.defaultSecondaryLocation
|
string
|
Región emparejada geográfica.
|
|
properties.earliestRestorePoint
|
string
(date-time)
|
Punto de restauración más antiguo en el tiempo para la restauración a un momento dado.
|
|
properties.extendedAccessibilityInfo
|
ManagedDatabaseExtendedAccessibilityInfo
|
Información adicional sobre observabilidad y solución de problemas para bases de datos en estado "Inaccesible".
|
|
properties.failoverGroupId
|
string
|
Identificador de recursos de grupo de conmutación por error de instancia al que pertenece esta base de datos administrada.
|
|
properties.isLedgerOn
|
boolean
|
Si esta base de datos es una base de datos de libro de contabilidad, lo que significa que todas las tablas de la base de datos son tablas de libro de contabilidad. Nota: El valor de esta propiedad no se puede cambiar después de crear la base de datos.
|
|
properties.lastBackupName
|
string
|
Último nombre de archivo de copia de seguridad para la restauración de esta base de datos administrada.
|
|
properties.longTermRetentionBackupResourceId
|
string
|
Nombre de la copia de seguridad de retención a largo plazo que se va a usar para restaurar esta base de datos administrada.
|
|
properties.recoverableDatabaseId
|
string
|
Identificador de recurso de la base de datos recuperable asociada a la operación de creación de esta base de datos.
|
|
properties.restorableDroppedDatabaseId
|
string
|
Identificador de recurso de base de datos restaurable que se va a restaurar al crear esta base de datos.
|
|
properties.restorePointInTime
|
string
(date-time)
|
Conditional. Si createMode es PointInTimeRestore, se requiere este valor. Especifica el momento dado (ISO8601 formato) de la base de datos de origen que se restaurará para crear la nueva base de datos.
|
|
properties.sourceDatabaseId
|
string
|
Identificador de recurso de la base de datos de origen asociada a la operación de creación de esta base de datos.
|
|
properties.status
|
ManagedDatabaseStatus
|
Estado de la base de datos.
|
|
properties.storageContainerIdentity
|
string
|
Conditional. Si createMode es RestoreExternalBackup, se usa este valor. Especifica la identidad usada para la autenticación del contenedor de almacenamiento. Puede ser "SharedAccessSignature" o "ManagedIdentity"; si no se especifica "SharedAccessSignature" se supone.
|
|
properties.storageContainerSasToken
|
string
|
Conditional. Si createMode es RestoreExternalBackup y storageContainerIdentity no es ManagedIdentity, se requiere este valor. Especifica el token sas del contenedor de almacenamiento.
|
|
properties.storageContainerUri
|
string
|
Conditional. Si createMode es RestoreExternalBackup, se requiere este valor. Especifica el URI del contenedor de almacenamiento donde se almacenan las copias de seguridad de esta restauración.
|
|
systemData
|
systemData
|
Azure Resource Manager metadatos que contienen información createdBy y modifiedBy.
|
|
tags
|
object
|
Etiquetas de recursos.
|
|
type
|
string
|
Tipo de recurso. Por ejemplo, "Microsoft. Compute/virtualMachines" o "Microsoft. CuentasAlmacenamiento/Almacenamiento"
|
ManagedDatabaseCreateMode
Enumeración
Modo de creación de base de datos administrada. PointInTimeRestore: cree una base de datos restaurando una copia de seguridad a un momento dado de una base de datos existente. SourceDatabaseName, SourceManagedInstanceName y PointInTime deben especificarse. RestoreExternalBackup: cree una base de datos restaurando a partir de archivos de copia de seguridad externos. Se deben especificar intercalación, StorageContainerUri y StorageContainerSasToken. Recuperación: crea una base de datos restaurando una copia de seguridad con replicación geográfica. RecoverableDatabaseId debe especificarse como identificador de recurso de base de datos recuperable que se va a restaurar. RestoreLongTermRetentionBackup: cree una base de datos restaurando a partir de una copia de seguridad de retención a largo plazo (se requiere longTermRetentionBackupResourceId).
| Valor |
Description |
|
Default
|
Predeterminado
|
|
RestoreExternalBackup
|
RestoreExternalBackup
|
|
PointInTimeRestore
|
PointInTimeRestore
|
|
Recovery
|
Recuperación
|
|
RestoreLongTermRetentionBackup
|
RestoreLongtermRetentionBackup
|
ManagedDatabaseExtendedAccessibilityInfo
Objeto
Información de accesibilidad extendida de la base de datos administrada
| Nombre |
Tipo |
Description |
|
inaccessibilityReasonDescription
|
string
|
Explicación de la causa raíz y acción de mitigación.
|
|
inaccessibilityReasonErrorCode
|
string
|
Código de error de SQL Server relacionado con la causa raíz de la inaccesibilidad.
|
|
inaccessibilityReasonKind
|
InaccessibilityReason
|
Tipo de causa raíz. Los valores permitidos son "TransparentDataEncryption", "DatabaseReplication" y "Unknown".
|
|
inaccessibilityReasonTdeKeyUri
|
string
|
Para el tipo de causa raíz "TransparentDataEncryption", el URI de CMK.
|
ManagedDatabaseStatus
Enumeración
Estado de la base de datos.
| Valor |
Description |
|
Online
|
En línea
|
|
Offline
|
Sin conexión
|
|
Shutdown
|
Apagar
|
|
Creating
|
Creando
|
|
Inaccessible
|
Inaccesible
|
|
Restoring
|
Restaurar
|
|
Updating
|
Actualización
|
|
Stopping
|
Parar
|
|
Stopped
|
Detenido
|
|
Starting
|
Iniciando
|
|
DbMoving
|
DbMoving
|
|
DbCopying
|
DbCopying
|
systemData
Objeto
Metadatos relativos a la creación y última modificación del recurso.
| Nombre |
Tipo |
Description |
|
createdAt
|
string
(date-time)
|
Marca de tiempo de creación de recursos (UTC).
|
|
createdBy
|
string
|
Identidad que creó el recurso.
|
|
createdByType
|
createdByType
|
Tipo de identidad que creó el recurso.
|
|
lastModifiedAt
|
string
(date-time)
|
La marca de tiempo de la última modificación del recurso (UTC)
|
|
lastModifiedBy
|
string
|
Identidad que modificó por última vez el recurso.
|
|
lastModifiedByType
|
createdByType
|
Tipo de identidad que modificó por última vez el recurso.
|