| title | Query SQL Database with Query editor in the Azure portal | |||||
|---|---|---|---|---|---|---|
| titleSuffix | Azure SQL Database | |||||
| description | Learn how to connect to an Azure SQL database and use the Azure portal Query editor (preview) to run Transact-SQL (T-SQL) queries. | |||||
| author | grrlgeek | |||||
| ms.author | jeschult | |||||
| ms.reviewer | wiassaf, mathoma, mbarickman | |||||
| ms.date | 03/20/2023 | |||||
| ms.service | sql-database | |||||
| ms.subservice | development | |||||
| ms.topic | quickstart | |||||
| ms.custom |
|
|||||
| keywords |
|
|||||
| monikerRange | = azuresql || = azuresql-db || = azuresql-mi |
[!INCLUDEappliesto-sqldb]
The Azure SQL Database Query editor (preview) is a tool to run SQL queries against Azure SQL Database in the Azure portal. In this quickstart, you connect to an Azure SQL database in the Azure portal and use query editor to run Transact-SQL (T-SQL) queries.
[!INCLUDE entra-id]
-
This quickstart uses the
AdventureWorksLTsample database in an Azure SQL database. If you don't have one already, you can create a database using sample data in Azure SQL Database. -
A user account with permissions to connect to the database and query editor. You can either:
- Have or set up a user that can connect to the database with SQL authentication.
- Have or set up a user that can authenticate to the database with Microsoft Entra ID (formerly Azure Active Directory).
-
On your SQL database Overview page in the Azure portal, select Query editor (preview) from the left menu.
:::image type="content" source="./media/connect-query-portal/find-query-editor.png" alt-text="Screenshot that shows selecting query editor.":::
-
On the sign-in screen, provide credentials to connect to the database. You can connect using SQL or Microsoft Entra authentication.
-
To connect with SQL authentication, under SQL server authentication, enter a Login and Password for a user that has access to the database, and then select OK. You can always use the login and password for the server admin.
:::image type="content" source="./media/connect-query-portal/login-menu.png" alt-text="Screenshot showing sign-in with SQL authentication.":::
-
To connect using Microsoft Entra ID, if you're the Microsoft Entra server admin, select Continue as <your user or group ID>. If sign-in is unsuccessful, try refreshing the page.
-
On the Query editor (preview) page, run the following example queries against your AdventureWorksLT sample database.
-
To query for the top 20 products in the database, paste the following SELECT query into the query editor:
SELECT TOP 20 pc.Name as CategoryName, p.name as ProductName FROM SalesLT.ProductCategory pc JOIN SalesLT.Product p ON pc.productcategoryid = p.productcategoryid;
-
Select Run, and then review the output in the Results pane.
:::image type="content" source="./media/connect-query-portal/query-editor-results.png" alt-text="Screenshot showing query editor results for a SELECT query.":::
-
Optionally, you can select Save query to save the query as an .sql file, or select Export data as to export the results as a .json, .csv, or .xml file.
To add a new product to the SalesLT.Product table, run the following INSERT T-SQL statement.
-
In the query editor, 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() );
-
Select Run to add the new product. After the query runs, the Messages pane displays Query succeeded: Affected rows: 1.
Run the following UPDATE T-SQL statement to update the price of your new product.
-
In the query editor, replace the previous query with the following query:
UPDATE [SalesLT].[Product] SET [ListPrice] = 125 WHERE Name = 'myNewProduct';
-
Select Run to update the specified row in the
Producttable. The Messages pane displays Query succeeded: Affected rows: 1.
Run the following DELETE T-SQL statement to remove your new product.
-
In the query editor, replace the previous query with the following query:
DELETE FROM [SalesLT].[Product] WHERE Name = 'myNewProduct';
-
Select Run to delete the specified row in the
Producttable. The Messages pane displays Query succeeded: Affected rows: 1.
- Query editor (preview)
- What is Azure SQL?
- Azure SQL glossary of terms
- T-SQL differences between SQL Server and Azure SQL Database
- Quickstart: Use Azure Data Studio to connect and query Azure SQL Database
- Quickstart: Use SSMS to connect to and query Azure SQL Database or Azure SQL Managed Instance
- Quickstart: Use Visual Studio Code to connect and query