DEV Community

yaswanthteja
yaswanthteja

Posted on

Create a SQL Database In Azure

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

The Create SQL Database Server pane appears.

  1. Enter the following values for each setting.

Image description

  1. Select** OK**.

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

Image description

Image description

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

Image description

Image description

  1. Select Next : Security, and for Enable Azure Defender for SQL, choose Not now. Leave the remaining settings as default (not configured).
    Image description

  2. Select Next : Additional settings, and configure the following settings.
    Image description

Image description

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

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

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

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

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

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

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

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

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

  1. Select Save to save this firewall rule.

Image description

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

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

  3. 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;
Enter fullscreen mode Exit fullscreen mode

Image description

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

Oldest comments (0)