Azure SQL Quickstart Tutorial
This tutorial will guide you through the essential steps to create and connect to an Azure SQL Database. By the end, you'll have a working SQL database ready for your applications.
Prerequisites
- An Azure account with an active subscription. If you don't have one, you can create a free account.
- A SQL Server management tool, such as SQL Server Management Studio (SSMS) or Azure Data Studio.
Step 1: Create an Azure SQL Database
Let's start by creating a new Azure SQL Database instance.
- Sign in to the Azure portal.
- In the search bar, type SQL databases and select it from the results.
- Click + Create.
- On the "Basics" tab, configure the following:
- Subscription: Select your subscription.
- Resource group: Create a new one (e.g.,
myResourceGroup
) or select an existing one. - Database name: Enter a unique name for your database (e.g.,
mySampleDatabase
). - Server:
- If you have an existing server, select it.
- Otherwise, click Create new and provide a server name (must be globally unique), administrator username, and password. Save these credentials securely!
- Compute + storage: For this quickstart, you can select the Basic service tier.
- Click Review + create, then click Create.
Step 2: Configure Firewall Rules
To connect to your database from your local machine or an application, you need to allow access through the Azure SQL Database firewall.
- Once the database deployment is complete, navigate to your newly created SQL database resource in the Azure portal.
- In the left-hand menu, under "Settings", select Firewalls and virtual networks.
- Under "Firewall rules", set Allow Azure services and resources to access this server to Yes.
- Click Add client IP to add your current public IP address to the allowed list.
- Click Save.
Step 3: Connect to Your Database
Now, let's connect to the database using your preferred SQL management tool.
Using SQL Server Management Studio (SSMS):
- Open SSMS.
- In the "Connect to Server" dialog:
- Server name: Enter the fully qualified server name (e.g.,
yourservername.database.windows.net
). You can find this on the database overview page in the Azure portal. - Authentication: Select SQL Server Authentication.
- Login: Enter the administrator username you created for the SQL server.
- Password: Enter the password for the administrator username.
- Server name: Enter the fully qualified server name (e.g.,
- Click Connect.
Using Azure Data Studio:
- Open Azure Data Studio.
- Click New Connection.
- In the "Connection details" pane:
- Connection type: Select Microsoft SQL Server.
- Server: Enter the fully qualified server name.
- Authentication type: Select SQL Login.
- User name: Enter your administrator username.
- Password: Enter your administrator password.
- Database: Leave blank for now, or select your newly created database.
- Server group: You can leave this as default.
- Click Connect.
Step 4: Run a Sample Query
Once connected, you can run a simple query to verify the connection.
SELECT @@VERSION;
This query should return information about your Azure SQL Database version.
Next Steps
Congratulations! You have successfully created and connected to an Azure SQL Database. You can now start designing your tables, inserting data, and building your applications.
- Learn more about designing tables in Azure SQL Database.
- Explore data manipulation techniques.
- Discover how to optimize database performance.