Create and connect to Azure SQL Database using Azure portal

This quickstart guides you through the steps to create an Azure SQL Database using the Azure portal and then connect to it using SQL Server Management Studio (SSMS).

Prerequisites

Step 1: Create an Azure SQL Database

Follow these steps to create a new Azure SQL Database:

  1. Sign in to the Azure portal.
  2. In the Azure portal search bar, type SQL databases and select it.
  3. Click + Create.
  4. On the Basics tab:
    • Subscription: Select your Azure subscription.
    • Resource group: Select an existing resource group or create a new one by clicking Create new.
    • Database name: Enter a unique name for your database (e.g., mydatabasequickstart).
    • Server:
      • If you have an existing SQL server, select it from the dropdown.
      • If you need to create a new server, click Create new. Provide a unique server name, choose a location, and set an administrator login and password.
    • Workload environment: Select Production or Development.
    • Compute + storage: Select a service tier and compute size. For this quickstart, the Basic tier is sufficient.
  5. Click Review + create and then Create.

Step 2: Connect to the Azure SQL Database using SSMS

Once your database is deployed, you can connect to it using SQL Server Management Studio (SSMS).

  1. In the Azure portal, navigate to your newly created Azure SQL database.
  2. On the database overview page, find and copy the Server name. It will look something like yourservername.database.windows.net.
  3. Open SQL Server Management Studio (SSMS).
  4. In the Connect to Server dialog:
    • Server type: Select Database Engine.
    • Server name: Paste the server name you copied from the Azure portal.
    • Authentication: Select SQL Server Authentication.
    • Login: Enter the administrator login name you created for your server.
    • Password: Enter the password for your administrator login.
  5. Click Connect.
Important: If you are unable to connect, you may need to configure firewall rules on your Azure SQL server to allow access from your IP address. You can do this in the Azure portal under your SQL server's Firewall rules settings.

Step 3: Create a sample table and insert data

Now that you're connected, let's run some Transact-SQL (T-SQL) commands to create a table and insert some data.

T-SQL

-- Create a new table called 'Customers'
CREATE TABLE Customers (
    CustomerID int IDENTITY(1,1) NOT NULL,
    CustomerName nvarchar(50) NOT NULL,
    ContactName nvarchar(50) NOT NULL,
    City nvarchar(50)
);

-- Insert rows into the 'Customers' table
INSERT INTO Customers (CustomerName, ContactName, City) VALUES
('Cardinal', 'Tom B. Erichsen', 'Stavanger'),
('Acme Corporation', 'Ann Beebe', 'Salt Lake City'),
('The Shire', 'Frodo Baggins', 'Hobbiton');

-- Select all rows from the 'Customers' table
SELECT * FROM Customers;
            

Step 4: Query the data

In SSMS, execute the following query to retrieve the data you just inserted:

T-SQL

SELECT * FROM Customers;
            

You should see the three rows you inserted into the Customers table.

Next Steps

Congratulations! You have successfully created an Azure SQL Database, connected to it, and run some basic queries. Here are some next steps: