Set Up Azure SQL Database

A Step-by-Step Guide to Getting Started

This tutorial will guide you through the process of creating and configuring an Azure SQL Database instance, a fully managed relational database service. It's designed for developers and administrators looking to leverage the power and scalability of SQL Server in the cloud.

Prerequisites

Steps to Set Up Azure SQL Database

1

Sign in to the Azure Portal

Open your web browser and navigate to the Azure portal. Sign in with your Azure account credentials.

Azure Portal Login Screen
2

Create a New SQL Database

In the Azure portal, select Create a resource from the home page. Search for SQL Database and select it. Click Create.

You'll be presented with a configuration blade:

  • Basics Tab:
    • Subscription: Choose your Azure subscription.
    • Resource group: Create a new one (e.g., sql-db-rg) or select an existing one.
    • Database name: Enter a unique name for your database (e.g., mydemosqldb).
    • Server: Click Create new and provide a server name (globally unique), administrator login, and password. Then click OK.
    • Workload environment: Select Development for testing or Production.
    • Compute + storage: Click Configure database. For testing, the Basic tier is often sufficient. Adjust the vCores and storage as needed.
  • Networking Tab:
    • Configure firewall rules to allow access to your server. For development, you might choose to Allow Azure services and resources to access this server.
    • You can add your client IP address to the firewall rules.
  • Security Tab:
    • Configure options like Microsoft Defender for SQL.
  • Additional settings Tab:
    • Choose a Data source. For a new database, select None. You can also restore from a backup or import from a BACPAC file.

Review your selections and click Review + create. Once validation passes, click Create.

Azure SQL Database Create Blade
3

Connect to Your SQL Database

Once the deployment is complete, navigate to your newly created SQL Database resource in the Azure portal. You'll find the Server name on the Overview page.

To connect:

  1. Open SQL Server Management Studio (SSMS) or Azure Data Studio.
  2. In the Connect to Server dialog:
    • Server name: Enter the server name obtained from the Azure portal.
    • Authentication: Select SQL Server Authentication.
    • Login: Enter the administrator login you created.
    • Password: Enter the password for the administrator login.
  3. Click Connect.

If you encounter connection issues, double-check your firewall rules in the Azure portal under the SQL server's Networking settings.

SSMS Connection Dialog
4

Create Tables and Insert Data

After connecting, you can start creating tables and inserting data. Here's a simple example:


-- Create a sample table
CREATE TABLE dbo.Products
(
    ProductID int NOT NULL PRIMARY KEY,
    ProductName varchar(50) NOT NULL,
    Price money
);

-- Insert some sample data
INSERT INTO dbo.Products (ProductID, ProductName, Price)
VALUES
(1, 'Laptop', 1200.00),
(2, 'Keyboard', 75.50),
(3, 'Mouse', 25.00);

-- Query the data
SELECT ProductID, ProductName, Price
FROM dbo.Products;
                    

Next Steps

Congratulations! You have successfully set up your Azure SQL Database and are ready to start building powerful data-driven applications.