Quickstart: Use the Azure portal query editor (preview) to query Azure SQL Database
Applies to:
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 portal and use query editor to run Transact-SQL (T-SQL) queries.
Prerequisites
The AdventureWorksLT sample Azure SQL database. If you don't have it, you can create a database in Azure SQL Database that has the AdventureWorks sample data.
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.
Set up an Azure Active Directory (Azure AD) administrator for the database's SQL server.
An Azure AD server administrator can use a single identity to sign in to the Azure portal and the SQL server and databases. To set up an Azure AD server admin:
In the Azure portal, on your Azure SQL database Overview page, select Server name under Essentials to navigate to the server for your database.
On the server page, select Azure Active Directory in the Settings section of the left menu.
On the Azure Active Directory page toolbar, select Set admin.
On the Azure Active Directory form, search for and select the user or group you want to be the admin, and then select Select.
On the Azure Active Directory main page, select Save.
Note
- Email addresses like outlook.com or gmail.com aren't supported as Azure AD admins. The user must either be created natively in the Azure AD or federated into the Azure AD.
- Azure AD admin sign-in works with accounts that have two-factor authentication enabled, but the query editor doesn't support two-factor authentication.
Connect to the query editor
On your SQL database Overview page in the Azure portal, select Query editor (preview) from the left menu.
On the sign-in screen, provide credentials to connect to the database. You can connect using SQL authentication or Azure AD.
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.
To connect using Azure AD, if you're the Azure AD server admin, select Continue as <your user or group ID>. If sign-in is unsuccessful, try refreshing the page.
Query the database
On the Query editor (preview) page, run the following example queries against your AdventureWorksLT sample database.
Run a SELECT query
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.
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.
Run an INSERT query
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 an UPDATE query
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 a DELETE query
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.
Considerations and limitations
The following considerations and limitations apply when connecting to and querying Azure SQL Database with the query editor.
Query editor limitations
- The query editor doesn't support connecting to the
masterdatabase. To connect to themasterdatabase, use SQL Server Management Studio (SSMS), Visual Studio Code, or Azure Data Studio. - The query editor can't connect to a replica database with
ApplicationIntent=ReadOnly. To connect in this way from a rich client, use SSMS and specifyApplicationIntent=ReadOnlyon the Additional Connection Parameters tab in connection options. For more information, see Connect to a read-only replica. - The query editor has a 5-minute timeout for query execution. To run longer queries, use SSMS, Visual Studio Code, or Azure Data Studio.
- The query editor only supports cylindrical projection for geography data types.
- The query editor doesn't support IntelliSense for database tables and views, but supports autocomplete for names that have already been typed. For IntelliSense support, use SSMS, Visual Studio Code, or Azure Data Studio.
- Pressing F5 refreshes the query editor page, and any query currently in the editor isn't saved.
Connection considerations
For public connections to the query editor, you need to add your outbound IP address to the server's allowed firewall rules to access your databases.
You don't need to add your IP address to the SQL server firewall rules if you have a Private Link connection set up on the server, and you connect to the server from within the private virtual network.
Users need at least the role-based access control (RBAC) permission Read access to the server and database to use the query editor. Anyone with this level of access can access the query editor. Users who can't assign themselves as the Azure AD admin or access a SQL administrator account shouldn't access the query editor.
Connection error troubleshooting
If you see the error message The X-CSRF-Signature header could not be validated, take the following actions to resolve the issue:
- Verify that your computer's clock is set to the right time and time zone. You can try to match your computer's time zone with Azure by searching for the time zone for your database location, such as East US.
- If you're on a proxy network, make sure that the request header
X-CSRF-Signatureisn't being modified or dropped.
You might get one of the following errors in the query editor:
- Your local network settings might be preventing the Query Editor from issuing queries. Please click here for instructions on how to configure your network settings.
- A connection to the server could not be established. This might indicate an issue with your local firewall configuration or your network proxy settings.
These errors occur because the query editor is unable to communicate through ports 443 and 1443. You need to enable outbound HTTPS traffic on these ports. The following instructions walk you through this process, depending on your OS. Your corporate IT department might need to grant approval to open this connection on your local network.
For Windows:
Open Windows Defender Firewall.
On the left menu, select Advanced settings.
In Windows Defender Firewall with Advanced Security, select Outbound rules on the left menu.
Select New Rule on the right menu.
In the New outbound rule wizard, follow these steps:
- Select port as the type of rule you want to create, and then select Next.
- Select TCP.
- Select Specific remote ports, enter 443, 1443, and then select Next.
- Select Allow the connection if it is secure, select Next, and then select Next again.
- Keep Domain, Private, and Public selected.
- Give the rule a name, for example Access Azure SQL query editor, and optionally provide a description. Then select Finish.
For MacOS:
- On the Apple menu, open System Preferences.
- Select Security & Privacy, and then select Firewall.
- If Firewall is off, select Click the lock to make changes at the bottom, and select Turn on Firewall.
- Select Firewall Options.
- In the Security & Privacy window, select Automatically allow signed software to receive incoming connections.
For Linux:
Run these commands to update
iptables:sudo iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT sudo iptables -A OUTPUT -p tcp --dport 1443 -j ACCEPT
Next steps
- What is Azure SQL?
- Azure SQL glossary of terms
- T-SQL differences between SQL Server and 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
- Quickstart: Use Azure Data Studio to connect and query Azure SQL Database
Feedback
Submit and view feedback for