Monday 19 September 2022

How to create Create a SQL database in Azure?

 Tailwind Traders has chosen Azure SQL Database for part of its migration. You've been tasked with creating the database.

In this exercise, 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.

    SettingValue
    Project details
    SubscriptionConcierge Subscription
    Resource group[Sandbox resource group]
    Database details
    Database namedb1
    ServerSelect Create new

    The Create SQL Database Server pane appears.

  4. Enter the following values for each setting.

    SettingValue
    Server details
    Server namesqlservernnnn (replace nnnn with letters and digits for a globally unique name)
    Location(US) East US
    Authentication
    Authentication methodUse SQL Authentication
    Server admin loginsqluser
    PasswordPa$$w0rd1234
  5. Select OK.

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

    SettingValue
    Want to use SQL elastic pool?No (default)
    Compute + storageGeneral Purpose (default)
    Backup storage redundancy
    Backup storage redundancyGeo-redundant backup storage

    Screenshot of create SQL database with fields filled in.

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

    SettingValue
    Network connectivity
    Connectivity methodPublic endpoint

    Screenshot of the Create SQL Database Networking tab with settings configured.

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

    Screenshot of the Create SQL Database Security tab showing the first configured setting.

  9. Select Next : Additional settings, and configure the following settings.

    SettingValue
    Data source
    Use existing dataSample
    Database collation
    CollationSQL_Latin1_General_CP1_CI_AS (default)

    Screenshot of the Additional settings tab of the Create SQL Database pane with settings selected.

  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.

    Screenshot of the SQL database Query editor preview.

  2. Select db1, the SQL database you created.

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

    Screenshot of the SQL database the Query editor preview highlighted.

  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.

    Screenshot of the Query Editor sign-in page with the IP address error.

  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.

    Screenshot of the SQL Server firewall settings page, with your IP settings and the command bar buttons highlighted.

  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.

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

    Screenshot of the query editor with the query pane, and the commands running successfully.

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

    Screenshot of the database query editor, showing the SQL code ran successfully and the output.

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

No comments:

Post a Comment