This tutorial guides you through the process of deploying and configuring a new Azure SQL database. We'll cover creating a server, setting up firewall rules, and creating your first database.

Prerequisites

Step 1: Create an Azure SQL Server

An Azure SQL server is a logical server that acts as a central administrative point for your databases. It hosts databases, manages logins, and handles authentication and authorization.

  1. Navigate to the Azure portal.
  2. Click on "Create a resource".
  3. Search for "Azure SQL" and select "Azure SQL database".
  4. Click "Create".
  5. In the "Basics" tab:
    • Subscription: Select your Azure subscription.
    • Resource group: Click "Create new" and enter a name (e.g., sql-rg).
    • Server name: Enter a globally unique name for your server (e.g., youruniquesqlservername).
    • Location: Choose a region closest to you or your users.
    • Server admin login: Create a username for the server administrator.
    • Password: Create a strong password and confirm it.
  6. Click "Next: Networking >".

Step 2: Configure Networking and Firewall Rules

For security, you need to configure firewall rules to allow access to your SQL server. By default, no external connections are allowed.

  1. In the "Networking" tab:
    • Public endpoint: Select "Enabled".
    • Allow Azure services and resources to access this server: Select "Yes" if you want other Azure services to connect.
    • Allow current client IP address: Select "Yes" to add your current IP address to the firewall rules, allowing you to connect from your machine.
  2. Click "Review + create".
  3. Once validation passes, click "Create".
Note: For production environments, it is highly recommended to configure more specific firewall rules instead of allowing all Azure services or only your client IP.

Step 3: Create a SQL Database

Now that your server is ready, you can create your first database on it.

  1. After the server deployment is complete, go to the server resource.
  2. Click on "Databases" under "Data management".
  3. Click "+ Create database".
  4. In the "Basics" tab:
    • Database name: Enter a name for your database (e.g., mydatabase).
    • Compute + storage: Click "Configure" to select a service tier and performance level. For this tutorial, the default "Basic" tier is sufficient.
  5. Click "Review + create".
  6. Click "Create".

Step 4: Connect to Your Database

You can connect to your Azure SQL database using various tools, such as SQL Server Management Studio (SSMS), Azure Data Studio, or programmatically using SDKs.

Using SQL Server Management Studio (SSMS)

  1. Open SSMS.
  2. In the "Connect to Server" dialog:
    • Server name: Enter your Azure SQL server name (e.g., youruniquesqlservername.database.windows.net).
    • Authentication: Select "SQL Server Authentication".
    • Login: Enter the server admin login you created.
    • Password: Enter the password for the server admin login.
  3. Click "Connect".
Tip: Ensure your client IP address is allowed through the server's firewall rules in the Azure portal.

Using Azure Data Studio

  1. Install and open Azure Data Studio.
  2. Click the "New Connection" button.
  3. In the "Connection" pane:
    • Connection type: Select "Microsoft SQL Server".
    • Server: Enter your Azure SQL server name.
    • Authentication type: Select "SQL Login".
    • User name: Enter your server admin login.
    • Password: Enter your password.
    • Database: Select your newly created database from the dropdown or leave as default for server-level access.
    • Encrypt: Select "True".
    • Trust server certificate: Select "True" if you are using a self-signed certificate or experiencing issues. (Not recommended for production).
  4. Click "Connect".

Next Steps

Congratulations! You have successfully deployed and configured an Azure SQL database. Here are some ideas for what to do next: