Forum Discussion
Can you create an SQL database table with columns via an Azure ARM Template?
Hi AlexGazz,
thanks for the update and your question.
It is possible to create a SQL server, database, and table in the same Azure Resource Manager (ARM) template. Here is an example how you can try to do it:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"serverName": {
"type": "string",
"metadata": {
"description": "The name of the Azure SQL server."
}
},
"databaseName": {
"type": "string",
"metadata": {
"description": "The name of the Azure SQL database."
}
}
},
"resources": [
{
"type": "Microsoft.Sql/servers",
"apiVersion": "2019-06-01-preview",
"name": "[parameters('serverName')]",
"location": "[resourceGroup().location]",
"properties": {
"administratorLogin": "your-admin-username",
"administratorLoginPassword": "your-admin-password"
},
"resources": [
{
"type": "databases",
"apiVersion": "2019-06-01-preview",
"name": "[concat(parameters('serverName'), '/', parameters('databaseName'))]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[parameters('serverName')]"
],
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
"edition": "Basic",
"maxSizeBytes": "1073741824"
},
"resources": [
{
"type": "tables",
"apiVersion": "2019-06-01-preview",
"name": "[concat(parameters('serverName'), '/', parameters('databaseName'), '/MyTable')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[parameters('databaseName')]"
],
"properties": {
"columns": [
{
"name": "Id",
"type": "int",
"isNullable": false,
"isIdentity": true,
"isPrimaryKey": true
},
{
"name": "Name",
"type": "nvarchar(50)",
"isNullable": false
},
{
"name": "Email",
"type": "nvarchar(100)",
"isNullable": true
}
]
}
}
]
}
]
}
]
}
You need to provide the appropriate values for the "administratorLogin" and "administratorLoginPassword" properties to set the admin credentials for the SQL server.
If you think my answer helped you, you can click on Mark as best response
Kindest regards
Leon Pavesic
LeonPavesic thank you for your message, unfortunately, the template you sent didn't work either. The deployment always fails when trying to create the table. I think I will try it another way: I'll make all the other resources via the template and then import the table using the import database functionality. Or I'm looking into using the BICEP files as these seem more user-friendly.