Open the firewall and run a query in the browser
In this task you'll run a SQL query from the portal.
The portal's Query editor lets you run SQL against your database straight from the browser, with nothing to install. It's handy for quick checks and small changes.
Before anything can connect, the server's firewall must allow the address it's coming from. If it doesn't, the connection is refused before anyone signs in.
Example. A Larkfield Group analyst gets a message that a product's price looks wrong on the website. They open Query editor, find the row with one SELECT, and confirm the price before raising a ticket.
Before you start
You need: Access to the database (as its Entra admin, or a database user). Time: 10 minutes.
Where to look
- SQL databases
- db-practice
- Query editor
Steps
- Open db-practice and select Query editor.
- On the Microsoft Entra authentication tab, select Connect as followed by your name.If you see a firewall error, it shows your IP address and offers to add it. Accept, or add it under the server's Networking page.
- Create a table: type
CREATE TABLE Products (Id INT PRIMARY KEY, Name NVARCHAR(50), Price DECIMAL(6,2));and select Run. - Add two rows:
INSERT INTO Products VALUES (1, 'Teapot', 18.50), (2, 'Mug', 6.00);and Run. - Read them back:
SELECT * FROM Products ORDER BY Price;and Run. The results appear below. - Open the server (select its name on the database's Overview) and select Networking to see the firewall rule for your address.
Commands
# Allow one IP address through the server firewall
az sql server firewall-rule create --resource-group rg-portal-practice \
--server sql-portal-<initials> --name allow-my-ip \
--start-ip-address <your IP> --end-ip-address <your IP>
# List the rules
az sql server firewall-rule list --resource-group rg-portal-practice \
--server sql-portal-<initials> --output table
Watch out for
- Cost
- Queries use the database's compute, which counts against the free allowance. A few small queries use almost none of it. The database pauses again when idle.
- Security
- Remove firewall rules for addresses you no longer use, such as a café's Wi-Fi. Never open the firewall to 0.0.0.0 to 255.255.255.255 to get past an error.
- Common mistakes
- Blaming sign-in when the real problem is the firewall. Using Query editor for big jobs: it has time and row limits, and proper tools such as SQL Server Management Studio or VS Code suit those better.
Clean up
Keep the table for the restore task. Remove your firewall rule from the server's Networking page when you've finished, or delete the resource group at the end of this section.
Words to know
- Server firewall
- Rules on the logical server that list which IP addresses may connect.
- T-SQL
- Transact-SQL: the SQL language used by SQL Server and Azure SQL.
- Query editor
- A simple SQL window in the portal, for small jobs.
Tick off each step and track your progress in the guide.
Open this task in Azure Portal, Hands On