Create a SQL Database In Azure
Tags: azure, beginners, tutorial, cloud
Published: 2022-05-21 16:05:52

Azure SQL Database for part of its migration. & creating the database.

 you'll create a SQL database in Azure and then query the data in that database.

## Task 1: Create the database

In this task, you'll create a SQL database based on the _AdventureWorksLT_ sample database.

1.Sign in to the Azure portal.

2.Select Create a resource > **Databases > SQL database**. The Create SQL Database pane appears.

3.Enter the following values for each setting.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3bm5y30gktu0nnz84zpf.png)

The **Create SQL Database** Server pane appears. 


4. Enter the following values for each setting.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xr05hxo9gxks4l11iolo.png)

5. Select** OK**. 

6. Complete the remaining fields for Create SQL Database using the following values.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nv1fiv7g0grk8a4ddh5c.png)


 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1noah688prg5iqd4tiub.png)


7. Select Next : **Networking**, and configure the following settings (accept defaults for fields not specified).

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i3y0yx33dhgw3l0dyq38.png)


 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c6e88i7wix78cc81i4g2.png
)


8. Select Next : Security, and for **Enable Azure Defender** for SQL, choose Not now. Leave the remaining settings as default (not configured).
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hlttsibdidvvrnt0lc67.png)

9. Select Next : **Additional settings**, and configure the following settings. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v7nen1u5ve8zeh3ex8q9.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0asecbh94qri3zc1g8wo.png)

10. Select** Review + create** to validate configuration entries.

11. Select **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.

12. When deployment is complete, select Go to resource. The db1 SQL database Overview pane shows the essentials of the newly deployed database.

13. In the command bar, **select Set server firewall**. The Firewall settings page appears.

14. 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.

15. Select Save to update firewall settings, then close the Firewall settings pane.

## Task 2: Test the database

In this task, you'll configure the server and run a SQL query.

1. 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i2hs5gvllhs4ui06xtzh.png)

2.Select db1, the SQL database you created.

3.In the SQL database menu,** select Query editor (preview). The Query editor (preview)** pane appears. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x6vp7uyhygp1uh7cbijj.png)

4. Sign in as **sqluser**, with the password **Pa$$w0rd1234.**

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o0rr042uzn8npfffgonk.png)
 
5. In the Query editor menu, select Overview (your edits will be lost), and in the command bar, select Set server firewall. The Firewall settings page appears.

6.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).

7.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.

8. Select Save to save this firewall rule.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6xbsahhhq7v9ptc71bgq.png)

9. Select your db1 database in the breadcrumb at the top of the page to return to your SQL database, and then select Query editor (preview) from the menu.

10. Sign in again as **sqluser**, with the password **Pa$$w0rd1234**. 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.

11. 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/egerhyv1tkaekai2o3l6.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sz6cu3b7p907xf60abq9.png)

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