Skip to content

Latest commit

 

History

History
165 lines (114 loc) · 7.28 KB

sql-database-connect-query-ssms.md

File metadata and controls

165 lines (114 loc) · 7.28 KB
title description keywords services ms.service ms.subservice ms.custom ms.devlang ms.topic author ms.author ms.reviewer manager ms.date
SSMS: Connect and query data in Azure SQL Database | Microsoft Docs
Learn how to connect to SQL Database on Azure by using SQL Server Management Studio (SSMS). Then run Transact-SQL (T-SQL) statements to query and edit data.
connect to sql database,sql server management studio
sql-database
sql-database
scenario
quickstart
CarlRabeler
carlrab
craigg
11/01/2018

Quickstart: Azure SQL Database: Use SQL Server Management Studio to connect and query data

SQL Server Management Studio (SSMS) is an integrated environment for managing any SQL infrastructure, from SQL Server to SQL Database for Microsoft Windows. This quickstart demonstrates how to use SSMS to connect to an Azure SQL database, and then use Transact-SQL statements to query, insert, update, and delete data in the database.

Prerequisites

This quickstart uses as its starting point the resources created in one of these quickstarts:

[!INCLUDE prerequisites-create-db]

This quickstart also requires that you configure a server-level firewall rule. For a quickstart showing how to do this, see Create server-level firewall rule.

Install the latest SSMS

Before you start, make sure you have installed the newest version of SSMS.

SQL server connection information

[!INCLUDE prerequisites-server-connection-info]

Connect to your database

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

Important

An Azure SQL Database logical server listens on port 1433. If you are attempting to connect to an Azure SQL Database logical server from within a corporate firewall, this port must be open in the corporate firewall for you to successfully connect.

  1. Open SQL Server Management Studio.

  2. In the Connect to Server dialog box, enter the following information:

    Setting     Suggested value Description 
    Server type Database engine This value is required.
    Server name The fully qualified server name The name should be something like this: mynewserver20170313.database.windows.net.
    Authentication SQL Server Authentication SQL Authentication is the only authentication type that we have configured in this tutorial.
    Login The server admin account This is the account that you specified when you created the server.
    Password The password for your server admin account This is the password that you specified when you created the server.

    connect to server

  3. Click Options in the Connect to server dialog box. In the Connect to database section, enter mySampleDatabase to connect to this database.

    connect to db on server

  4. Click Connect. The Object Explorer window opens in SSMS.

    connected to server

  5. In Object Explorer, expand Databases and then expand mySampleDatabase to view the objects in the sample database.

Query data

Use the following code to query for the top 20 products by category using the SELECT Transact-SQL statement.

  1. In Object Explorer, right-click mySampleDatabase and click New Query. A blank query window opens that is connected to your database.

  2. In the query window, enter the following query:

    SELECT pc.Name as CategoryName, p.name as ProductName
    FROM [SalesLT].[ProductCategory] pc
    JOIN [SalesLT].[Product] p
    ON pc.productcategoryid = p.productcategoryid;
  3. On the toolbar, click Execute to retrieve data from the Product and ProductCategory tables.

    query

Insert data

Use the following code to insert a new product into the SalesLT.Product table using the INSERT Transact-SQL statement.

  1. In the query window, replace the previous query with the following query:

    INSERT INTO [SalesLT].[Product]
            ( [Name]
            , [ProductNumber]
            , [Color]
            , [ProductCategoryID]
     	   , [StandardCost]
     	   , [ListPrice]
     	   , [SellStartDate]
     	   )
      VALUES
            ('myNewProduct'
            ,123456789
            ,'NewColor'
            ,1
     	   ,100
     	   ,100
     	   ,GETDATE() );
  2. On the toolbar, click Execute to insert a new row in the Product table.

    insert

Update data

Use the following code to update the new product that you previously added using the UPDATE Transact-SQL statement.

  1. In the query window, replace the previous query with the following query:

    UPDATE [SalesLT].[Product]
    SET [ListPrice] = 125
    WHERE Name = 'myNewProduct';
  2. On the toolbar, click Execute to update the specified row in the Product table.

    update

Delete data

Use the following code to delete the new product that you previously added using the DELETE Transact-SQL statement.

  1. In the query window, replace the previous query with the following query:

    DELETE FROM [SalesLT].[Product]
    WHERE Name = 'myNewProduct';
  2. On the toolbar, click Execute to delete the specified row in the Product table.

    delete

Next steps