Quickstart: Use Azure Data Studio to connect and query Azure SQL database

This quickstart demonstrates how to use Azure Data Studio to connect to an Azure SQL Database server and then use Transact-SQL (T-SQL) statements to create and query the TutorialDB database, which is used in other Azure Data Studio tutorials.


To complete this quickstart, you need Azure Data Studio, and an Azure SQL Database server.

If you don't already have an Azure SQL server, complete one of the following Azure SQL Database quickstarts (remember the fully qualified server name and sign in credentials for steps in the next section):

Connect to your Azure SQL Database server

Use Azure Data Studio to establish a connection to your Azure SQL Database server.

  1. The first time you run Azure Data Studio the Connection page should open. If you don't see the Connection page, select Add Connection, or the New Connection icon in the SERVERS sidebar:

    New Connection Icon

  2. This article uses SQL Login, but Windows Authentication is also supported. Fill in the following fields using the server name, user name, and password for your Azure SQL server:

    Setting Suggested value Description
    Server name The fully qualified server name Something like: servername.database.windows.net.
    Authentication SQL Login This tutorial uses SQL Authentication.
    User name The server admin account user name The user name from the account used to create the server.
    Password (SQL Login) The server admin account password The password from the account used to create the server.
    Save Password? Yes or No Select Yes if you don't want to enter the password each time.
    Database name leave blank You're only connecting to the server here.
    Server Group Select You can set this to a specific server group you created.

    New Connection Icon

  3. Select Connect.

  4. If your server doesn't have a firewall rule allowing Azure Data Studio to connect, the Create new firewall rule form opens. Complete the form to create a new firewall rule. For details, see Firewall rules.

    New firewall rule

After successfully connecting, your server opens in the SERVERS sidebar.

Create the tutorial database

The following sections create the TutorialDB database that's used in other Azure Data Studio tutorials.

  1. Right-click on your Azure SQL server in the SERVERS sidebar and select New Query.

  2. Paste the following SQL snippet into the query editor.

       SELECT name
       FROM sys.databases
       WHERE name = N'TutorialDB'
  3. Select Run. Notifications appear in the MESSAGES pane showing query progress.

Create a table

The query editor is still connected to the master database, but we want to create a table in the TutorialDB database.

  1. Connect to the TutorialDB database:

    Change context

  2. Create a Customers table.

    Overwrite the previous query in the query editor with this SQL snippet and select Run.

    -- Create a new table called 'Customers' in schema 'dbo'
    -- Drop the table if it already exists
    IF OBJECT_ID('dbo.Customers', 'U') IS NOT NULL
    DROP TABLE dbo.Customers
    -- Create the table in the specified schema
    CREATE TABLE dbo.Customers
       CustomerId        INT    NOT NULL   PRIMARY KEY, -- primary key column
       Name      [NVARCHAR](50)  NOT NULL,
       Location  [NVARCHAR](50)  NOT NULL,
       Email     [NVARCHAR](50)  NOT NULL

Insert rows into the table

Overwrite the previous query in the query editor with this SQL snippet and select Run.

-- Insert rows into table 'Customers'
INSERT INTO dbo.Customers
   ( 1, N'Orlando', N'Australia', N''),
   ( 2, N'Keith', N'India', N'keith0@adventure-works.com'),
   ( 3, N'Donna', N'Germany', N'donna0@adventure-works.com'),
   ( 4, N'Janet', N'United States', N'janet1@adventure-works.com')

View the result

Overwrite the previous query in the query editor with this SQL snippet and select Run.

-- Select rows from table 'Customers'
SELECT * FROM dbo.Customers;

The query results display:

Select results

Clean up resources

Later quickstart articles build upon the resources created here. If you plan to work through these articles, be sure not to delete these resources. Otherwise, in the Azure portal, you can delete the resources you no longer need. For details, see Clean up resources.

Next steps

Now that you have successfully connected to an Azure SQL database and run a query, try out the Code editor tutorial.