Are you interested in learning how to write SQL queries and understand how SQL Server databases work? Most online resources use the free sample database AdventureWorks, which is installed on an on-premises SQL Server. But what if you want to learn how the cloud version, Azure SQL Database, works? In this tutorial, we will guide you through the steps to create a SQL Server instance in the Azure cloud and install the AdventureWorksLT sample database, a lightweight version of the original AdventureWorks database.
Step 1: Create a New SQL Server Instance in Azure
To get started, log into the Azure Portal using a browser. On the home page, click on “Create a resource” and search for SQL Server in the Marketplace. Select SQL Server (logical server) from the results. This logical server will host your Azure SQL Databases and allow you to configure properties such as the firewall and admin account.
In the overview screen, click on “Create” and choose a subscription, resource group, and region for your server. You can create a new resource group if you haven’t already. Provide a globally unique name for the server and choose the authentication method (Azure Active Directory or SQL authentication).
In the Networking tab, allow Azure services and resources to access the server. This firewall rule enables Azure services to connect to the SQL Server over the network. Click on “Review + create” and then “Create” to create the server instance.
Step 2: Configure Firewall Rules and Install AdventureWorksLT Database
After the server has been created, go to the Networking section and add your own IP address to the firewall rules. This is important for accessing your database later on. Don’t forget to save the changes.
Next, go to the overview pane and click on “Create database” to add a new database. Most information will already be filled in, so you just need to specify a name for the database. For the other settings, choose a development workload and set the redundancy to locally-redundant backup storage (LRS).
Configure the size of the database using the DTU-based purchasing model. The Basic tier is suitable for small-scale test scenarios, while the Standard tier is recommended for sample databases. You can find a mapping between the service tiers and the number of DTUs in the Azure pricing calculator.
Once you’ve configured the size, go to the Networking tab and add your IP address to the server firewall rules. In the Additional settings, change the slider for “Use existing data” to “Sample”. This will create the database by restoring a backup of the AdventureWorksLT sample database.
Review the settings and click on “Create” to start the deployment of your new resource. This may take a few minutes. If you want to change the pricing tier later on, you can do so from the overview pane.
Step 3: Query the Data in the AdventureWorksLT Sample Database
Now that your database is ready, you can start querying the data using T-SQL statements. You can use tools like Azure Data Studio or SQL Server Management Studio (SSMS) to connect to the database instance.
In SSMS, connect to the database instance using the server name you created earlier. Depending on your server configuration, you can connect using Azure AD or SQL authentication. Before connecting, go to Options and change the master database to the name of your sample database. This is important for non-administrator users to avoid connection issues.
Once connected, you can view all the tables in the AdventureWorksLT sample database and start querying the data.
By following these steps, you can create an Azure SQL Database instance and install the AdventureWorksLT sample database. This will allow you to practice writing SQL queries and gain a better understanding of how SQL Server databases work in the cloud.
Happy querying!