Introduction to Azure SQL Database

Azure SQL Database is a fully managed Platform as a Service (PaaS) database engine that handles most of the database management functions such as upgrading, patching, backups, and monitoring without user involvement.

This tutorial will walk you through the fundamental concepts and steps to get started with Azure SQL Database.

Key Concepts

  • Database Server: A logical container that hosts a collection of databases.
  • Database: An individual, structured collection of data.
  • Firewall Rules: Controls access to your Azure SQL Database server by specifying which IP addresses are allowed to connect.
  • Connection Strings: A string containing the information necessary to connect to a database.
  • SQL Server Management Studio (SSMS): A popular graphical tool for managing SQL Server instances and Azure SQL Databases.

Step 1: Create an Azure SQL Database Server

Before you can create a database, you need an Azure SQL Database server.

  1. Sign in to the Azure portal.
  2. In the Azure portal, search for and select "SQL servers".
  3. Click "Create".
  4. Fill in the required details: Subscription, Resource group, Server name, Location, Administrator username, and Password.
  5. Click "Review + create" and then "Create".
Azure Portal SQL Server Creation

Figure 1: Creating a new Azure SQL Server in the Azure portal.

Step 2: Create a Database

Once your server is provisioned, you can create a database on it.

  1. Navigate to your newly created SQL server in the Azure portal.
  2. In the server overview page, click "Create database".
  3. Enter a database name, select a compute and storage configuration (e.g., Basic, Standard, Premium tiers), and optionally configure other settings.
  4. Click "Review + create" and then "Create".

You can also create a database from an existing backup or a sample database.

Step 3: Configure Firewall Rules

By default, your Azure SQL Database server is protected by a firewall. You need to configure rules to allow access from your IP address or a range of IP addresses.

  1. Go to your SQL server's page in the Azure portal.
  2. Under "Security", click "Networking".
  3. Select "Selected networks".
  4. Under "Firewall rules", click "Add your client IP". This will automatically add a rule for your current public IP address.
  5. You can also manually add a rule by specifying a name, start IP address, and end IP address.
  6. Click "Save".
Important: Never disable the firewall completely unless you have a specific, secure reason to do so. Always restrict access to the minimum necessary IP addresses.

Step 4: Connect to Your Database

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

Using SQL Server Management Studio (SSMS)

  1. Download and install SQL Server Management Studio if you haven't already.
  2. Open SSMS and in the "Connect to Server" dialog, enter the Server name (e.g., yourserver.database.windows.net).
  3. Select "SQL Server Authentication" as the Authentication type.
  4. Enter the Login (your administrator username) and Password you created when provisioning the server.
  5. Click "Connect".

Using Azure Data Studio

Azure Data Studio is a cross-platform database tool.

  1. Download and install Azure Data Studio.
  2. Open Azure Data Studio and click "New Connection".
  3. Enter the connection details similar to SSMS.

You can find your server's fully qualified domain name (FQDN) on the server's overview page in the Azure portal.

Step 5: Querying Your Database

Once connected, you can execute SQL queries.

Example: Creating a simple table and inserting data

-- Create a table
CREATE TABLE Products (
    ProductID INT PRIMARY KEY IDENTITY(1,1),
    ProductName VARCHAR(100) NOT NULL,
    Price DECIMAL(10, 2)
);

-- Insert some data
INSERT INTO Products (ProductName, Price) VALUES
('Laptop', 1200.50),
('Keyboard', 75.00),
('Mouse', 25.99);

-- Select data
SELECT ProductID, ProductName, Price
FROM Products;

Next Steps

Congratulations! You've successfully set up and connected to your Azure SQL Database.

  • Explore different service tiers and performance options.
  • Learn about security best practices, including Azure Active Directory authentication.
  • Discover high availability and disaster recovery features.
  • Integrate your database with other Azure services like Azure Functions or Azure App Service.