You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Learn how to connect to SQL Database in the Azure portal by using the SQL Query Editor. Then, run Transact-SQL (T-SQL) statements to query and edit data.
4
-
keywords: connect to sql database,azure portal, portal, query editor
2
+
title: Query a SQL Database using the query editor in the Azure portal
3
+
description: Learn how to use the Query Editor to run Transact-SQL (T-SQL) queries against an Azure SQL Database.
# Quickstart: Use the Azure portal's SQL query editor to connect and query data
16
+
# Quickstart: Use the Azure portal's query editor to query a SQL database
17
+
18
+
The query editor is a tool in the Azure portal for running SQL queries against your Azure SQL database or Azure SQL Data Warehouse.
19
+
20
+
In this quickstart, you'll use the query editor to run Transact-SQL (T-SQL) queries against an Azure SQL database.
17
21
18
-
The SQL query editor is an Azure portal browser tool providing an easy way to execute SQL queries on your Azure SQL Database or Azure SQL Data Warehouse. In this quickstart, you'll use the query editor to connect to a SQL database and then run Transact-SQL statements to query, insert, update, and delete data.
19
22
20
23
## Prerequisites
21
24
22
-
To complete this tutorial, you need:
25
+
Completing this quickstart requires the AdventureWorksLT sample database. If you don't have a working copy of the AdventureWorksLT SQL database, the following quickstart quickly creates one:
23
26
24
-
-An Azure SQL database. You can use one of these quickstarts to create and then configure a database in Azure SQL Database:
27
+
-[Quickstart: Create a single Azure SQL database using the Azure portal, PowerShell, or Azure CLI](sql-database-single-database-get-started.md)
| Configure |[Server-level IP firewall rule](sql-database-server-level-firewall-rule.md)|
32
-
|||
29
+
### Configure network settings
33
30
34
-
> [!NOTE]
35
-
> The query editor uses ports 443 and 1443 to communicate. Please ensure you have enabled outbound HTTPS traffic on these ports. You will also need to add your outbound IP address to the server's allowed firewall rules to access your databases and data warehouses.
31
+
If you 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*, or *A connection to the server could not be established. This might indicate an issue with your local firewall configuration or your network proxy settings*, the following important information should help resolve:
36
32
37
-
## Sign in the Azure portal
33
+
> [!IMPORTANT]
34
+
> The query editor uses ports 443 and 1443 to communicate. Ensure you have enabled outbound HTTPS traffic on these ports. You also need to [add your outbound IP address to the server's allowed firewall rules](sql-database-server-level-firewall-rule.md) to access your databases and data warehouses.
38
35
39
-
Sign in to the [Azure portal](https://portal.azure.com/).
40
36
41
-
## Connect using SQL authentication
37
+
## Open the SQL Database Query Editor
42
38
43
-
1.Go to the Azure portal to connect to a SQL database. Search for and select **SQL databases**.
39
+
1.Sign in to the [Azure portal](https://portal.azure.com/) and select the SQL database you want to query.
44
40
45
-

41
+
2. In the **SQL database** menu, select **Query editor (preview)**.
Even though you're signed into the portal, you still need to provide credentials to access the SQL database. You can connect using SQL authentication or Azure Active Directory to connect to your database.
49
+
50
+
### Connect using SQL Authentication
54
51
55
-
4. In the **Login** page, under the **SQL server authentication** label, enter the**Login**ID and **Password**of the server admin account used to create the database. Then select **OK**.
52
+
1. In the **Login** page, under **SQL server authentication**, enter a**Login** and **Password**for a user that has access to the database. If you're not sure, use the login and password for the Server admin of the database's server.
Configuring an Azure Active Directory (Azure AD) administrator enables you to use a single identity to sign in to the Azure portal and your SQL database. Follow the steps below to configure an Azure AD admin for your SQL server.
58
+
59
+
### Connect using Azure Active Directory
60
+
61
+
Configuring an Azure Active Directory (Azure AD) administrator enables you to use a single identity to sign in to the Azure portal and your SQL database. To connect to your database using Azure AD, follow the steps below to configure an Azure AD admin for your SQL server.
62
62
63
63
> [!NOTE]
64
64
> * Email accounts (for example, outlook.com, gmail.com, yahoo.com, and so on) aren't yet supported as Azure AD admins. Make sure to choose a user created either natively in the Azure AD, or federated into the Azure AD.
65
65
> * Azure AD admin sign in doesn't work with accounts that have 2-factor authentication enabled.
66
66
67
-
1. On the Azure portal menu or from the **Home** page, select **All resources**.
67
+
#### Set an Active Directory admin for the database server
68
68
69
-
2. Select your SQL server.
69
+
1. In the Azure portal, select your SQL server.
70
70
71
-
3. From the **SQL server** menu, under **Settings**, select **Active Directory admin**.
71
+
2. On the **SQL server** menu, select **Active Directory admin**.
72
72
73
-
4. From the SQL server **Active Directory admin** page toolbar, select **Set admin** and choose the user or group as your Azure AD admin.
73
+
3. On the SQL server **Active Directory admin** page toolbar, select **Set admin** and choose the user or group as your Azure AD admin.
74
74
75
75

76
76
77
-
5. From the **Add admin** page, in the search box, enter a user or group to find, select it as an admin, and then choose the **Select** button.
77
+
4. On the **Add admin** page, in the search box, enter a user or group to find, select it as an admin, and then choose the **Select** button.
78
+
79
+
5. Back in the SQL server **Active Directory admin** page toolbar, select **Save**.
78
80
79
-
6. Back in the SQL server **Active Directory admin** page toolbar, select **Save**.
81
+
### Connect to the database
80
82
81
-
7. In the **SQL server** menu, select **SQL databases**, and then select your SQL database.
83
+
6. In the **SQL server** menu, select **SQL databases**, and then select your SQL database.
82
84
83
-
8. In the **SQL database** menu, select **Query editor (preview)**. In the **Login** page, under the **Active Directory authentication** label, a message appears saying you have been signed in if you're an Azure AD admin. Then select the **Continue as***\<your user or group ID>* button.
85
+
7. In the **SQL database** menu, select **Query editor (preview)**. In the **Login** page, under the **Active Directory authentication** label, a message appears saying you have been signed in if you're an Azure AD admin. Then select the **Continue as***\<your user or group ID>* button. If the page indicates that you have not successfully logged in, you may need to refresh the page.
84
86
85
-
## View data
87
+
## Query a SQL database
86
88
87
-
1. After you're authenticated, paste the following SQL in the query editor to retrieve the top 20 products by category.
89
+
The following example queries should run successfully against the AdventureWorksLT sample database.
90
+
91
+
### Run a SELECT query
92
+
93
+
1. Paste the following query into the query editor:
88
94
89
95
```sql
90
96
SELECT TOP 20pc.Nameas CategoryName, p.nameas ProductName
@@ -93,13 +99,15 @@ Configuring an Azure Active Directory (Azure AD) administrator enables you to us
93
99
ONpc.productcategoryid=p.productcategoryid;
94
100
```
95
101
96
-
2.On the toolbar, select**Run** and then review the output in the **Results** pane.
102
+
2.Select**Run** and then review the output in the **Results** pane.
3. Optionally, you can save the query as a .sql file, or export the returned data as a .json, .csv, or .xml file.
107
+
108
+
### Run an INSERT query
101
109
102
-
Run the following [INSERT](https://msdn.microsoft.com/library/ms174335.aspx) Transact-SQL statement to add a new product in the `SalesLT.Product` table.
110
+
Run the following [INSERT](/sql/t-sql/statements/insert-transact-sql/) T-SQL statement to add a new product in the `SalesLT.Product` table.
103
111
104
112
1. Replace the previous query with this one.
105
113
@@ -127,9 +135,9 @@ Run the following [INSERT](https://msdn.microsoft.com/library/ms174335.aspx) Tra
127
135
2. Select **Run** to insert a new row in the `Product` table. The **Messages** pane displays **Query succeeded: Affected rows: 1**.
128
136
129
137
130
-
##Update data
138
+
### Run an UPDATE query
131
139
132
-
Run the following [UPDATE](https://msdn.microsoft.com/library/ms177523.aspx) Transact-SQL statement to modify your new product.
140
+
Run the following [UPDATE](/sql/t-sql/queries/update-transact-sql/) T-SQL statement to modify your new product.
133
141
134
142
1. Replace the previous query with this one.
135
143
@@ -141,9 +149,9 @@ Run the following [UPDATE](https://msdn.microsoft.com/library/ms177523.aspx) Tra
141
149
142
150
2. Select **Run** to update the specified row in the `Product` table. The **Messages** pane displays **Query succeeded: Affected rows: 1**.
143
151
144
-
##Delete data
152
+
### Run a DELETE query
145
153
146
-
Run the following [DELETE](https://msdn.microsoft.com/library/ms189835.aspx) Transact-SQL statement to remove your new product.
154
+
Run the following [DELETE](/sql/t-sql/statements/delete-transact-sql/) T-SQL statement to remove your new product.
147
155
148
156
1. Replace the previous query with this one:
149
157
@@ -159,23 +167,23 @@ Run the following [DELETE](https://msdn.microsoft.com/library/ms189835.aspx) Tra
159
167
160
168
There are a few things to know when working with the query editor.
161
169
162
-
* The query editor uses ports 443 and 1443 to communicate. Please ensure you have enabled outbound HTTPS traffic on these ports. You will also need to add your outbound IP address to the server's allowed firewall rules to access your databases and data warehouses.
170
+
* The query editor uses ports 443 and 1443 to communicate. Ensure you have enabled outbound HTTPS traffic on these ports. You will also need to add your outbound IP address to the server's allowed firewall rules to access your databases and data warehouses.
163
171
164
172
* Query Editor works with Private Link without needing to add the Client Ip address into the SQL Database firewall
165
173
166
-
* Pressing F5 refreshes the query editor page and any query being worked on is lost.
174
+
* Pressing **F5** refreshes the query editor page and any query being worked on is lost.
167
175
168
176
* Query editor doesn't support connecting to the `master` database.
169
177
170
178
* There's a 5-minute timeout for query execution.
171
179
172
180
* The query editor only supports cylindrical projection for geography data types.
173
181
174
-
* There's no support for IntelliSense for database tables and views. However, the editor does support autocomplete on names that have already been typed.
182
+
* There's no support for IntelliSense for database tables and views, but the editor does support autocomplete on names that have already been typed.
175
183
176
184
177
185
178
186
179
187
## Next steps
180
188
181
-
To learn more about the Transact-SQL supported in Azure SQL databases, see [Resolving Transact-SQL differences during migration to SQL Database](sql-database-transact-sql-information.md).
189
+
To learn more about the Transact-SQL (T-SQL) supported in Azure SQL databases, see [Resolving Transact-SQL differences during migration to SQL Database](sql-database-transact-sql-information.md).
0 commit comments