Skip to content

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:

  • master
  • model
  • tempdb

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 name property to a string that matches the naming requirements.
  • Optionally, consider constraining name parameters with minLength and maxLength attributes.

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 name property to a string that matches the naming requirements.
  • Optionally, consider constraining name parameters with minLength and maxLength attributes.
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.

Comments