Use valid SQL Database names#
Operational Excellence · SQL Database · Rule · 2020_12 · Awareness
Azure SQL Database names should meet naming requirements.
Description#
When naming Azure resources, resource names must meet service requirements. The requirements for SQL Database names are:
- Between 1 and 128 characters long.
- Letters, numbers, and special characters except:
<>*%&:\/? - Can't end with period or a space.
- Must be unique for each logical server.
The following reserved database names can not be used:
mastermodeltempdb
Recommendation#
Consider using names that meet Azure SQL Database naming requirements. Additionally consider naming resources with a standard naming convention.
Examples#
Configure with Bicep#
To deploy databases that pass this rule:
- Set the
nameproperty to a string that matches the naming requirements. - Optionally, consider constraining name parameters with
minLengthandmaxLengthattributes.
For example:
Azure Bicep snippet
@minLength(1)
@maxLength(128)
@description('The name of the resource.')
param name string
@description('The location resources will be deployed.')
param location string = resourceGroup().location
resource database 'Microsoft.Sql/servers/databases@2024-05-01-preview' = {
parent: server
name: name
location: location
properties: {
collation: 'SQL_Latin1_General_CP1_CI_AS'
maxSizeBytes: maxSize
catalogCollation: 'SQL_Latin1_General_CP1_CI_AS'
readScale: 'Disabled'
zoneRedundant: true
}
}
Configure with Azure template#
To deploy databases that pass this rule:
- Set the
nameproperty to a string that matches the naming requirements. - Optionally, consider constraining name parameters with
minLengthandmaxLengthattributes.
Azure Template snippet
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"type": "string",
"minLength": 1,
"maxLength": 128,
"metadata": {
"description": "The name of the resource."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "The location resources will be deployed."
}
}
},
"resources": [
{
"type": "Microsoft.Sql/servers/databases",
"apiVersion": "2024-05-01-preview",
"name": "[format('{0}/{1}', parameters('name'), parameters('name'))]",
"location": "[parameters('location')]",
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"maxSizeBytes": "[variables('maxSize')]",
"catalogCollation": "SQL_Latin1_General_CP1_CI_AS",
"readScale": "Disabled",
"zoneRedundant": true
}
}
]
}
Notes#
This rule does not check if Azure SQL Database names are unique.
Links#
- OE:04 Continuous integration
- Operational Excellence: Level 2
- Recommended abbreviations for Azure resource types
- Naming rules and restrictions for Azure resources
- Define your naming convention
- Parameters in Bicep
- Bicep functions
- Azure deployment reference