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 |
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.
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.
Before you start, make sure you have installed the newest version of SSMS.
[!INCLUDE prerequisites-server-connection-info]
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.
-
Open SQL Server Management Studio.
-
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. -
Click Options in the Connect to server dialog box. In the Connect to database section, enter mySampleDatabase to connect to this database.
-
Click Connect. The Object Explorer window opens in SSMS.
-
In Object Explorer, expand Databases and then expand mySampleDatabase to view the objects in the sample database.
Use the following code to query for the top 20 products by category using the SELECT Transact-SQL statement.
-
In Object Explorer, right-click mySampleDatabase and click New Query. A blank query window opens that is connected to your database.
-
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;
-
On the toolbar, click Execute to retrieve data from the Product and ProductCategory tables.
Use the following code to insert a new product into the SalesLT.Product table using the INSERT Transact-SQL statement.
-
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() );
-
On the toolbar, click Execute to insert a new row in the Product table.
Use the following code to update the new product that you previously added using the UPDATE Transact-SQL statement.
-
In the query window, replace the previous query with the following query:
UPDATE [SalesLT].[Product] SET [ListPrice] = 125 WHERE Name = 'myNewProduct';
-
On the toolbar, click Execute to update the specified row in the Product table.
Use the following code to delete the new product that you previously added using the DELETE Transact-SQL statement.
-
In the query window, replace the previous query with the following query:
DELETE FROM [SalesLT].[Product] WHERE Name = 'myNewProduct';
-
On the toolbar, click Execute to delete the specified row in the Product table.
- For information about SSMS, see Use SQL Server Management Studio.
- To connect and query using the Azure portal, see Connect and query with the Azure portal SQL Query editor.
- To connect and query using Visual Studio Code, see Connect and query with Visual Studio Code.
- To connect and query using .NET, see Connect and query with .NET.
- To connect and query using PHP, see Connect and query with PHP.
- To connect and query using Node.js, see Connect and query with Node.js.
- To connect and query using Java, see Connect and query with Java.
- To connect and query using Python, see Connect and query with Python.
- To connect and query using Ruby, see Connect and query with Ruby.