MSDN Documentation

Getting Started with Azure SQL Database

Welcome to the getting started guide for Azure SQL Database. This comprehensive guide will walk you through the initial steps to create, configure, and connect to your first Azure SQL Database instance.

What is Azure SQL Database?

Azure SQL Database is a fully managed Platform as a Service (PaaS) database engine that handles most database management functions such as upgrading, patching, backups, and provides 99.99% high availability. It is built on the SQL Server engine, offering familiar tools and capabilities.

Prerequisites

  • An active Azure subscription. If you don't have one, you can sign up for a free trial.
  • Basic understanding of relational databases and SQL.

Steps to Get Started

Step 1: Create an Azure SQL Database Server

Before you can create a database, you need to provision a logical SQL server. This server acts as a central administration point for a collection of databases.

  1. Sign in to the Azure portal.
  2. In the portal, search for "SQL servers" and select "SQL servers" from the list.
  3. Click "Create".
  4. Fill out the required fields: Subscription, Resource group, Server name (must be globally unique), Location, and Administrator login credentials.
  5. Click "Review + create" and then "Create" to provision your server.

Step 2: Create a SQL Database

Once your SQL server is deployed, you can create your first SQL database.

  1. Navigate to your newly created SQL server in the Azure portal.
  2. Under "Data management", select "Databases".
  3. Click "Create database".
  4. Provide a database name, select your server, choose a compute + storage option (e.g., Basic, Standard, Premium, or Serverless), and configure other settings as needed.
  5. Click "Review + create" and then "Create".

Step 3: Configure Firewall Rules

By default, Azure SQL Database servers block all external connections. You need to configure firewall rules to allow access from your IP address or other trusted sources.

  1. Navigate back to your SQL server in the Azure portal.
  2. Under "Security", select "Networking".
  3. Under "Firewalls rules", click "Add a firewall rule".
  4. Provide a rule name, and specify the Start and End IP addresses. To allow access from your current IP, you can often use the "Add your current client IP address" button.
  5. Click "Save".

Step 4: Connect to Your Database

You can now connect to your Azure SQL Database using various tools.

Using Azure Data Studio (Recommended)

Azure Data Studio is a cross-platform database tool that works great with Azure SQL Database.

  1. Download and install Azure Data Studio.
  2. Open Azure Data Studio and click the "New Connection" button.
  3. In the connection details, enter:
    • Server: Your SQL server name (e.g., your-server-name.database.windows.net)
    • Authentication type: SQL Login
    • User name: Your administrator login username
    • Password: Your administrator login password
  4. Click "Connect".

Using SQL Server Management Studio (SSMS)

If you are using Windows, SSMS is a powerful option.

  1. Download and install SQL Server Management Studio.
  2. Open SSMS and in the "Connect to Server" dialog, enter your server name, authentication details, and click "Connect".

Connecting Programmatically

You can connect using various programming languages and libraries. Here's a C# example using the Microsoft.Data.SqlClient library:


using Microsoft.Data.SqlClient;
using System;

public class Program
{
    public static void Main(string[] args)
    {
        string connectionString = "Server=tcp:your-server-name.database.windows.net,1433;Initial Catalog=your-database-name;Persist Security Info=False;User ID=your-username;Password=your-password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;";

        using (var connection = new SqlConnection(connectionString))
        {
            try
            {
                connection.Open();
                Console.WriteLine("Connection successful!");

                // Example query
                // using (var command = new SqlCommand("SELECT @@VERSION", connection))
                // {
                //     var result = command.ExecuteScalar();
                //     Console.WriteLine($"SQL Server Version: {result}");
                // }
            }
            catch (SqlException e)
            {
                Console.WriteLine(e.ToString());
            }
        }
    }
}
                

Next Steps

Congratulations! You have successfully set up and connected to your Azure SQL Database. Now you can start creating tables, inserting data, and building your applications.

Explore further by:

Create Your First Database Now