Azure Documentation

Learn how to build and manage applications on Microsoft Azure.

Azure SQL Quickstart Tutorial

This tutorial will guide you through the essential steps to create and connect to an Azure SQL Database. By the end, you'll have a working SQL database ready for your applications.

Prerequisites

Step 1: Create an Azure SQL Database

Let's start by creating a new Azure SQL Database instance.

  1. Sign in to the Azure portal.
  2. In the search bar, type SQL databases and select it from the results.
  3. Click + Create.
  4. On the "Basics" tab, configure the following:
    • Subscription: Select your subscription.
    • Resource group: Create a new one (e.g., myResourceGroup) or select an existing one.
    • Database name: Enter a unique name for your database (e.g., mySampleDatabase).
    • Server:
      • If you have an existing server, select it.
      • Otherwise, click Create new and provide a server name (must be globally unique), administrator username, and password. Save these credentials securely!
    • Compute + storage: For this quickstart, you can select the Basic service tier.
  5. Click Review + create, then click Create.
Tip: Creating a new SQL server also provisions a logical SQL server. This logical server acts as a central administrative point for a collection of databases.

Step 2: Configure Firewall Rules

To connect to your database from your local machine or an application, you need to allow access through the Azure SQL Database firewall.

  1. Once the database deployment is complete, navigate to your newly created SQL database resource in the Azure portal.
  2. In the left-hand menu, under "Settings", select Firewalls and virtual networks.
  3. Under "Firewall rules", set Allow Azure services and resources to access this server to Yes.
  4. Click Add client IP to add your current public IP address to the allowed list.
  5. Click Save.

Step 3: Connect to Your Database

Now, let's connect to the database using your preferred SQL management tool.

Using SQL Server Management Studio (SSMS):

  1. Open SSMS.
  2. In the "Connect to Server" dialog:
    • Server name: Enter the fully qualified server name (e.g., yourservername.database.windows.net). You can find this on the database overview page in the Azure portal.
    • Authentication: Select SQL Server Authentication.
    • Login: Enter the administrator username you created for the SQL server.
    • Password: Enter the password for the administrator username.
  3. Click Connect.

Using Azure Data Studio:

  1. Open Azure Data Studio.
  2. Click New Connection.
  3. In the "Connection details" pane:
    • Connection type: Select Microsoft SQL Server.
    • Server: Enter the fully qualified server name.
    • Authentication type: Select SQL Login.
    • User name: Enter your administrator username.
    • Password: Enter your administrator password.
    • Database: Leave blank for now, or select your newly created database.
    • Server group: You can leave this as default.
  4. Click Connect.

Step 4: Run a Sample Query

Once connected, you can run a simple query to verify the connection.

SELECT @@VERSION;

This query should return information about your Azure SQL Database version.

Next Steps

Congratulations! You have successfully created and connected to an Azure SQL Database. You can now start designing your tables, inserting data, and building your applications.