Azure SQL Database is a **fully managed relational database service** by Microsoft. It is based on SQL Server and provides high availability, security, and scalability.
Azure SQL Database - Complete Guide
What is Azure SQL Database?
Azure SQL Database is a **fully managed relational database service** by Microsoft. It is based on SQL Server and provides high availability, security, and scalability.
Why Use Azure SQL Database?
- Fully Managed: No need to manage hardware, patching, or backups.
- High Availability: Built-in disaster recovery with **99.99% uptime**.
- Automatic Scaling: Adapts to changing workloads.
- Advanced Security: Encryption, authentication, and firewall rules.
- Serverless Option: Pay only for what you use.
Creating an Azure SQL Database
Step 1: Create a SQL Server
az sql server create --name my-sql-server --resource-group MyResourceGroup --location eastus --admin-user myadmin --admin-password MySecureP@ssword
Step 2: Create a Database
az sql db create --resource-group MyResourceGroup --server my-sql-server --name mydatabase --service-objective S0
Step 3: Configure Firewall Rules
az sql server firewall-rule create --resource-group MyResourceGroup --server my-sql-server --name AllowYourIP --start-ip-address 0.0.0.0 --end-ip-address 255.255.255.255
Connecting to Azure SQL Database
Using Azure Data Studio
1️⃣ Open **Azure Data Studio**
2️⃣ Click **New Connection** and enter:
- Server:
my-sql-server.database.windows.net
- Database:
mydatabase
- Username:
myadmin
- Password:
MySecureP@ssword
3️⃣ Click **Connect**
Using Python (SQLAlchemy)
from sqlalchemy import create_engine
server = 'my-sql-server.database.windows.net'
database = 'mydatabase'
username = 'myadmin'
password = 'MySecureP@ssword'
engine = create_engine(f'mssql+pyodbc://{username}:{password}@{server}/{database}?driver=ODBC+Driver+17+for+SQL+Server')
conn = engine.connect()
print("Connected successfully!")
Scaling Azure SQL Database
Change Performance Tier
az sql db update --resource-group MyResourceGroup --server my-sql-server --name mydatabase --service-objective P1
Backup and Restore
Perform a Manual Backup
az sql db export --resource-group MyResourceGroup --server my-sql-server --name mydatabase --storage-key MyStorageKey --storage-uri https://mystorageaccount.blob.core.windows.net/backups/mydatabase.bacpac
Restore from Backup
az sql db import --resource-group MyResourceGroup --server my-sql-server --name restored-db --storage-key MyStorageKey --storage-uri https://mystorageaccount.blob.core.windows.net/backups/mydatabase.bacpac
Monitoring Performance
az monitor metrics list --resource /subscriptions/MY_SUBSCRIPTION_ID/resourceGroups/MyResourceGroup/providers/Microsoft.Sql/servers/my-sql-server/databases/mydatabase --metric "dtu_consumption_percent"
Conclusion
Azure SQL Database is a powerful **cloud-based relational database** with **automatic scaling, built-in security, and high availability**.
📌 Next Topic: Azure Cosmos DB - Globally Distributed NoSQL Database