DEV Community

Toluwani Oluwaloseyi
Toluwani Oluwaloseyi

Posted on

How to Create a SQL Database in Azure, Test the Database, configure the server and run a SQL query.

Image description

Azure SQL Database is a fully managed platform as a service (PaaS) database engine that handles most of the database management functions such as upgrading, patching, backups, and monitoring without user involvement.

Step 1:
Sign in to the Azure portal. (portal.azure.com)

Step 2:
Search for SQL Database, click on create.

Image description

Step 3:

  • Subscription: Choose the subscription where you wish to create the resource.
  • Resource group: Choose the resource group where you wish to create the resource. If you wish to create a new group click on create a new option.
  • Database Name: Enter a preferred unique name.(i chose tolu SQLdatabase)
  • Server: Create a new unique name (I chose toluserver)
  • Location: EastUS
  • Authentication method: Use SQL authentication
  • Server admin login: azureuser
  • Password: Password12345
  • Backup storage redundancy: Geo redundant backup storage
  • Region: Select the location where you wish to create the account.

Image description

Image description

Step 4:
Click on "Next : Networking"
Connectivity method: public endpoint

Image description

Step 5:
Click on "Next : Security", and for Enable Azure Defender for SQL, choose Not now. Leave the remaining settings as default

Image description

Step 6:
Click on "Next : Additional settings"
Use existing data: Sample

Click on "Review + create"

Image description

Step 8:
Click on "create" to deploy the server and database. It can take approximately two to five minutes to create the server and deploy the sample database. The deployment pane shows the status, with updates for each resource that is created.

Image description

Step 9:
Click on "Go to resource". The toluSQLdatabase Overview pane shows the essentials of the newly deployed database

Image description

Step 10:
Click on "Set server firewall". The Firewall settings page appears.

Image description

Step 11:
Check the box next to Allow Azure services and resources to access this server at the bottom of the page, leaving other settings as default and then "Save" to update firewall settings, then close the Firewall settings pane.

Image description

Step 12:

How to Test the database

Here, we'll configure the server and run a SQL query.

In Azure resources menu, select All resources. Search for and select the SQL database resource Type, and ensure that your new database was created. You might need to refresh the page.

Image description

Image description

Step 13:
Click on "toludatabase", i.e the SQL database you created. In the SQL database menu, select Query editor (preview). The Query editor (preview) pane appears.

Image description

Step 14:
Sign in as azureuser, with the password Password12345.

You will not be able to sign in because your IP address needs to be enabled in a firewall rule.

Image description

Step 15:
Click on "Overview" (your edits will be lost), and in the command bar, select Set server firewall. The Firewall settings page appears.

Image description

Image description

Step 16:
In the Client IP address section, your IP will be shown (verify that it is the same client IP address from the error you received in the previous step).

In the command bar select Add your client IPv4 address. This will add a Rule name that contains your IP address in both the Start IP and End IP fields and the Click on "Save"

Image description

Step 17:
Click on toludatabase (database you created) in the breadcrumb at the top of the page to return to your SQL database, and then select Query editor (preview) from the menu.

Step 18:
Sign in again as azureuser, with the password Password12345. This time you should succeed. It might take a couple of minutes for the new firewall rule to be deployed. If you still get an error, verify the client IP address in the error, and return to Firewall settings to add the correct client IP address.

Image description

Step 19:
After you sign in successfully, the query pane appears. Enter the following SQL query into the editor pane.

SELECT TOP 20 pc.Name as CategoryName, p.name as ProductName
FROM SalesLT.ProductCategory pc
JOIN SalesLT.Product p
ON pc.productcategoryid = p.productcategoryid;

Image description

Step 20:
Select Run, and then review the query results in the Results pane. The query should run successfully.

Image description

Congratulations! You've created a SQL database in Azure and successfully queried the data in that database.

Thank you for reading...

Top comments (0)