@KaisMalique-9406 Thank you for reaching out.
Yes, you will be able to retreive the costs for each Azure SQL Database. You can also choose to tag them individually for convinience.
From your Azure Portal, please navigate to Cost Management.
Click on the Cost Analysis blade and filter by the Tag and/or Resource Type for any particular billing period
You will be able to see the resource cost per database on the server and also export them to Excel by clicking on the Download button.
In this case, I have 2 Azure SQL Databases, 1 Datawarehouse and 1 Elastic pool all running on the same Server and I can retreive the costs separately.
If you want to get these details programatically, you can use the Azure CostManagement Query - Usage API and fetch these details.
RequestBody for Post call:
Modify the filters and timeperiod as per your needs
{"type":"ActualCost","dataSet":{"granularity":"None","aggregation":{"totalCost":{"name":"PreTaxCost","function":"Sum"}},"grouping":[{"type":"Dimension","name":"ResourceId"}]},"timeframe":"Custom","timePeriod":{"from":"2020-7-1T00:00:00+00:00","to":"2020-7-31T00:00:00+00:00"}}
Results:
{
"id": "subscriptions/*******-****-****-****-******/providers/Microsoft.CostManagement/query/*******-****-****-****-******",
"name": "*******-****-****-****-******",
"type": "Microsoft.CostManagement/query",
"location": null,
"sku": null,
"eTag": null,
"properties": {
"nextLink": "https://management.azure.com/subscriptions/*******-****-****-****-******/providers/Microsoft.CostManagement/query?api-version=2019-10-01&$top=1000&$skiptoken=AQAAAA%3D%3D",
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceId",
"type": "String"
},
{
"name": "Currency",
"type": "String"
}
],
"rows": [
[
28.100787,
"/subscriptions/*******-****-****-****-******/resourcegroups/myteam-resources/providers/microsoft.sql/servers/sqlserverleon/databases/db2",
"USD"
],
[
37.771289,
"/subscriptions/*******-****-****-****-******/resourcegroups/myteam-resources/providers/microsoft.sql/servers/sqlserverleon/databases/leonpool",
"USD"
],
[
1.19945,
"/subscriptions/*******-****-****-****-******/resourcegroups/myteam-resources/providers/microsoft.sql/servers/sqlserverleon/databases/mydatabase",
"USD"
],
[
3.79819,
"/subscriptions/*******-****-****-****-******/resourcegroups/myteam-resources/providers/microsoft.sql/servers/sqlserverleon/databases/mydatabase1",
"USD"
]
]
}
}
I hope this helps. Please let us know if you have further questions
If an Answer is helpful, please “Accept Answer” or Up-Vote for the same which might be beneficial to other community members reading this thread.