Creates a new database or updates an existing database.
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}?api-version=2025-01-01
URI Parameters
| Name |
In |
Required |
Type |
Description |
|
databaseName
|
path |
True
|
string
|
The name of the database.
|
|
managedInstanceName
|
path |
True
|
string
|
The name of the managed instance.
|
|
resourceGroupName
|
path |
True
|
string
minLength: 1 maxLength: 90
|
The name of the resource group. The name is case insensitive.
|
|
subscriptionId
|
path |
True
|
string
(uuid)
|
The ID of the target subscription. The value must be an UUID.
|
|
api-version
|
query |
True
|
string
minLength: 1
|
The API version to use for this operation.
|
Request Body
| Name |
Required |
Type |
Description |
|
location
|
True
|
string
|
The geo-location where the resource lives
|
|
properties.autoCompleteRestore
|
|
boolean
|
Whether to auto complete restore of this managed database.
|
|
properties.catalogCollation
|
|
CatalogCollationType
|
Collation of the metadata catalog.
|
|
properties.collation
|
|
string
|
Collation of the managed database.
|
|
properties.createMode
|
|
ManagedDatabaseCreateMode
|
Managed database create mode. PointInTimeRestore: Create a database by restoring a point in time backup of an existing database. SourceDatabaseName, SourceManagedInstanceName and PointInTime must be specified. RestoreExternalBackup: Create a database by restoring from external backup files. Collation, StorageContainerUri and StorageContainerSasToken must be specified. Recovery: Creates a database by restoring a geo-replicated backup. RecoverableDatabaseId must be specified as the recoverable database resource ID to restore. RestoreLongTermRetentionBackup: Create a database by restoring from a long term retention backup (longTermRetentionBackupResourceId required).
|
|
properties.crossSubscriptionRestorableDroppedDatabaseId
|
|
string
|
The restorable cross-subscription dropped database resource id to restore when creating this database.
|
|
properties.crossSubscriptionSourceDatabaseId
|
|
string
|
The resource identifier of the cross-subscription source database associated with create operation of this database.
|
|
properties.crossSubscriptionTargetManagedInstanceId
|
|
string
|
Target managed instance id used in cross-subscription restore.
|
|
properties.isLedgerOn
|
|
boolean
|
Whether or not this database is a ledger database, which means all tables in the database are ledger tables. Note: the value of this property cannot be changed after the database has been created.
|
|
properties.lastBackupName
|
|
string
|
Last backup file name for restore of this managed database.
|
|
properties.longTermRetentionBackupResourceId
|
|
string
|
The name of the Long Term Retention backup to be used for restore of this managed database.
|
|
properties.recoverableDatabaseId
|
|
string
|
The resource identifier of the recoverable database associated with create operation of this database.
|
|
properties.restorableDroppedDatabaseId
|
|
string
|
The restorable dropped database resource id to restore when creating this database.
|
|
properties.restorePointInTime
|
|
string
(date-time)
|
Conditional. If createMode is PointInTimeRestore, this value is required. Specifies the point in time (ISO8601 format) of the source database that will be restored to create the new database.
|
|
properties.sourceDatabaseId
|
|
string
|
The resource identifier of the source database associated with create operation of this database.
|
|
properties.storageContainerIdentity
|
|
string
|
Conditional. If createMode is RestoreExternalBackup, this value is used. Specifies the identity used for storage container authentication. Can be 'SharedAccessSignature' or 'ManagedIdentity'; if not specified 'SharedAccessSignature' is assumed.
|
|
properties.storageContainerSasToken
|
|
string
|
Conditional. If createMode is RestoreExternalBackup and storageContainerIdentity is not ManagedIdentity, this value is required. Specifies the storage container sas token.
|
|
properties.storageContainerUri
|
|
string
|
Conditional. If createMode is RestoreExternalBackup, this value is required. Specifies the uri of the storage container where backups for this restore are stored.
|
|
tags
|
|
object
|
Resource tags.
|
Responses
| Name |
Type |
Description |
|
200 OK
|
ManagedDatabase
|
Resource 'ManagedDatabase' update operation succeeded
|
|
201 Created
|
ManagedDatabase
|
Resource 'ManagedDatabase' create operation succeeded
Headers
- Location: string
- Retry-After: integer
|
|
202 Accepted
|
|
Resource operation accepted.
Headers
- Location: string
- Retry-After: integer
|
|
Other Status Codes
|
ErrorResponse
|
An unexpected error response.
|
Security
azure_auth
Azure Active Directory OAuth2 Flow.
Type:
oauth2
Flow:
implicit
Authorization URL:
https://login.microsoftonline.com/common/oauth2/authorize
Scopes
| Name |
Description |
|
user_impersonation
|
impersonate your user account
|
Examples
Creates a new managed database by restoring from an external backup
Sample request
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://learn.microsoft.com/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
Sample response
{
"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
Sample request
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://learn.microsoft.com/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
Sample response
{
"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
Sample request
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://learn.microsoft.com/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
Sample response
{
"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
Sample request
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://learn.microsoft.com/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
Sample response
{
"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
Sample request
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://learn.microsoft.com/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
Sample response
{
"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
Sample request
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://learn.microsoft.com/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
Sample response
{
"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.
Sample request
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://learn.microsoft.com/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
Sample response
{
"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
Sample request
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://learn.microsoft.com/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
Sample response
{
"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
Sample request
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://learn.microsoft.com/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
Sample response
{
"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
Definitions
| Name |
Description |
|
CatalogCollationType
|
Collation of the metadata catalog.
|
|
createdByType
|
The type of identity that created the resource.
|
|
ErrorAdditionalInfo
|
The resource management error additional info.
|
|
ErrorDetail
|
The error detail.
|
|
ErrorResponse
|
Error response
|
|
InaccessibilityReason
|
Root cause kind. Allowed values are “TransparentDataEncryption”, “DatabaseReplication”, and “Unknown”.
|
|
ManagedDatabase
|
A managed database resource.
|
|
ManagedDatabaseCreateMode
|
Managed database create mode. PointInTimeRestore: Create a database by restoring a point in time backup of an existing database. SourceDatabaseName, SourceManagedInstanceName and PointInTime must be specified. RestoreExternalBackup: Create a database by restoring from external backup files. Collation, StorageContainerUri and StorageContainerSasToken must be specified. Recovery: Creates a database by restoring a geo-replicated backup. RecoverableDatabaseId must be specified as the recoverable database resource ID to restore. RestoreLongTermRetentionBackup: Create a database by restoring from a long term retention backup (longTermRetentionBackupResourceId required).
|
|
ManagedDatabaseExtendedAccessibilityInfo
|
Managed Database Extended Accessibility Information
|
|
ManagedDatabaseStatus
|
Status of the database.
|
|
systemData
|
Metadata pertaining to creation and last modification of the resource.
|
CatalogCollationType
Enumeration
Collation of the metadata catalog.
| Value |
Description |
|
DATABASE_DEFAULT
|
DATABASE_DEFAULT
|
|
SQL_Latin1_General_CP1_CI_AS
|
SQL_Latin1_General_CP1_CI_AS
|
createdByType
Enumeration
The type of identity that created the resource.
| Value |
Description |
|
User
|
|
|
Application
|
|
|
ManagedIdentity
|
|
|
Key
|
|
ErrorAdditionalInfo
Object
The resource management error additional info.
| Name |
Type |
Description |
|
info
|
object
|
The additional info.
|
|
type
|
string
|
The additional info type.
|
ErrorDetail
Object
The error detail.
| Name |
Type |
Description |
|
additionalInfo
|
ErrorAdditionalInfo[]
|
The error additional info.
|
|
code
|
string
|
The error code.
|
|
details
|
ErrorDetail[]
|
The error details.
|
|
message
|
string
|
The error message.
|
|
target
|
string
|
The error target.
|
ErrorResponse
Object
Error response
| Name |
Type |
Description |
|
error
|
ErrorDetail
|
The error object.
|
InaccessibilityReason
Enumeration
Root cause kind. Allowed values are “TransparentDataEncryption”, “DatabaseReplication”, and “Unknown”.
| Value |
Description |
|
Unknown
|
Unknown
|
|
TransparentDataEncryption
|
TransparentDataEncryption
|
|
DatabaseReplication
|
DatabaseReplication
|
ManagedDatabase
Object
A managed database resource.
| Name |
Type |
Description |
|
id
|
string
(arm-id)
|
Fully qualified resource ID for the resource. E.g. "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}"
|
|
location
|
string
|
The geo-location where the resource lives
|
|
name
|
string
|
The name of the resource
|
|
properties.autoCompleteRestore
|
boolean
|
Whether to auto complete restore of this managed database.
|
|
properties.catalogCollation
|
CatalogCollationType
|
Collation of the metadata catalog.
|
|
properties.collation
|
string
|
Collation of the managed database.
|
|
properties.createMode
|
ManagedDatabaseCreateMode
|
Managed database create mode. PointInTimeRestore: Create a database by restoring a point in time backup of an existing database. SourceDatabaseName, SourceManagedInstanceName and PointInTime must be specified. RestoreExternalBackup: Create a database by restoring from external backup files. Collation, StorageContainerUri and StorageContainerSasToken must be specified. Recovery: Creates a database by restoring a geo-replicated backup. RecoverableDatabaseId must be specified as the recoverable database resource ID to restore. RestoreLongTermRetentionBackup: Create a database by restoring from a long term retention backup (longTermRetentionBackupResourceId required).
|
|
properties.creationDate
|
string
(date-time)
|
Creation date of the database.
|
|
properties.crossSubscriptionRestorableDroppedDatabaseId
|
string
|
The restorable cross-subscription dropped database resource id to restore when creating this database.
|
|
properties.crossSubscriptionSourceDatabaseId
|
string
|
The resource identifier of the cross-subscription source database associated with create operation of this database.
|
|
properties.crossSubscriptionTargetManagedInstanceId
|
string
|
Target managed instance id used in cross-subscription restore.
|
|
properties.defaultSecondaryLocation
|
string
|
Geo paired region.
|
|
properties.earliestRestorePoint
|
string
(date-time)
|
Earliest restore point in time for point in time restore.
|
|
properties.extendedAccessibilityInfo
|
ManagedDatabaseExtendedAccessibilityInfo
|
Additional observability and troubleshooting information for databases in ‘Inaccessible’ state.
|
|
properties.failoverGroupId
|
string
|
Instance Failover Group resource identifier that this managed database belongs to.
|
|
properties.isLedgerOn
|
boolean
|
Whether or not this database is a ledger database, which means all tables in the database are ledger tables. Note: the value of this property cannot be changed after the database has been created.
|
|
properties.lastBackupName
|
string
|
Last backup file name for restore of this managed database.
|
|
properties.longTermRetentionBackupResourceId
|
string
|
The name of the Long Term Retention backup to be used for restore of this managed database.
|
|
properties.recoverableDatabaseId
|
string
|
The resource identifier of the recoverable database associated with create operation of this database.
|
|
properties.restorableDroppedDatabaseId
|
string
|
The restorable dropped database resource id to restore when creating this database.
|
|
properties.restorePointInTime
|
string
(date-time)
|
Conditional. If createMode is PointInTimeRestore, this value is required. Specifies the point in time (ISO8601 format) of the source database that will be restored to create the new database.
|
|
properties.sourceDatabaseId
|
string
|
The resource identifier of the source database associated with create operation of this database.
|
|
properties.status
|
ManagedDatabaseStatus
|
Status of the database.
|
|
properties.storageContainerIdentity
|
string
|
Conditional. If createMode is RestoreExternalBackup, this value is used. Specifies the identity used for storage container authentication. Can be 'SharedAccessSignature' or 'ManagedIdentity'; if not specified 'SharedAccessSignature' is assumed.
|
|
properties.storageContainerSasToken
|
string
|
Conditional. If createMode is RestoreExternalBackup and storageContainerIdentity is not ManagedIdentity, this value is required. Specifies the storage container sas token.
|
|
properties.storageContainerUri
|
string
|
Conditional. If createMode is RestoreExternalBackup, this value is required. Specifies the uri of the storage container where backups for this restore are stored.
|
|
systemData
|
systemData
|
Azure Resource Manager metadata containing createdBy and modifiedBy information.
|
|
tags
|
object
|
Resource tags.
|
|
type
|
string
|
The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts"
|
ManagedDatabaseCreateMode
Enumeration
Managed database create mode. PointInTimeRestore: Create a database by restoring a point in time backup of an existing database. SourceDatabaseName, SourceManagedInstanceName and PointInTime must be specified. RestoreExternalBackup: Create a database by restoring from external backup files. Collation, StorageContainerUri and StorageContainerSasToken must be specified. Recovery: Creates a database by restoring a geo-replicated backup. RecoverableDatabaseId must be specified as the recoverable database resource ID to restore. RestoreLongTermRetentionBackup: Create a database by restoring from a long term retention backup (longTermRetentionBackupResourceId required).
| Value |
Description |
|
Default
|
Default
|
|
RestoreExternalBackup
|
RestoreExternalBackup
|
|
PointInTimeRestore
|
PointInTimeRestore
|
|
Recovery
|
Recovery
|
|
RestoreLongTermRetentionBackup
|
RestoreLongTermRetentionBackup
|
ManagedDatabaseExtendedAccessibilityInfo
Object
Managed Database Extended Accessibility Information
| Name |
Type |
Description |
|
inaccessibilityReasonDescription
|
string
|
Root cause explanation and mitigation action.
|
|
inaccessibilityReasonErrorCode
|
string
|
SQL Server error code connected to the inaccessibility root cause.
|
|
inaccessibilityReasonKind
|
InaccessibilityReason
|
Root cause kind. Allowed values are “TransparentDataEncryption”, “DatabaseReplication”, and “Unknown”.
|
|
inaccessibilityReasonTdeKeyUri
|
string
|
For the root cause kind “TransparentDataEncryption”, the CMK URI.
|
ManagedDatabaseStatus
Enumeration
Status of the database.
| Value |
Description |
|
Online
|
Online
|
|
Offline
|
Offline
|
|
Shutdown
|
Shutdown
|
|
Creating
|
Creating
|
|
Inaccessible
|
Inaccessible
|
|
Restoring
|
Restoring
|
|
Updating
|
Updating
|
|
Stopping
|
Stopping
|
|
Stopped
|
Stopped
|
|
Starting
|
Starting
|
|
DbMoving
|
DbMoving
|
|
DbCopying
|
DbCopying
|
systemData
Object
Metadata pertaining to creation and last modification of the resource.
| Name |
Type |
Description |
|
createdAt
|
string
(date-time)
|
The timestamp of resource creation (UTC).
|
|
createdBy
|
string
|
The identity that created the resource.
|
|
createdByType
|
createdByType
|
The type of identity that created the resource.
|
|
lastModifiedAt
|
string
(date-time)
|
The timestamp of resource last modification (UTC)
|
|
lastModifiedBy
|
string
|
The identity that last modified the resource.
|
|
lastModifiedByType
|
createdByType
|
The type of identity that last modified the resource.
|