Get Started with Azure SQL Database
Welcome to Azure SQL Database! This guide will walk you through the essential steps to create and connect to your first Azure SQL Database instance. Whether you're building a new application or migrating an existing one, Azure SQL Database provides a powerful, scalable, and fully managed relational database service.
- How to create an Azure SQL Database server and database.
- How to configure firewall rules.
- How to connect to your database using SQL Server Management Studio (SSMS).
Prerequisites
Before you begin, ensure you have the following:
- An active Azure account. If you don't have one, you can create a free account for 12 months.
- A web browser.
- SQL Server Management Studio (SSMS) installed on your local machine. Download SSMS here.
Step 1: Create an Azure SQL Database Server and Database
You can create your Azure SQL Database resources through the Azure portal, Azure CLI, or PowerShell. This guide will use the Azure portal for simplicity.
Sign in to the Azure portal.
In the Azure portal search bar, type "SQL databases" and select SQL databases from the results.
Click + Create to open the "Create SQL database" page.
On the Basics tab:
- Subscription: Select your Azure subscription.
- Resource group: Create a new one (e.g., `sql-db-rg`) or select an existing one.
- Database name: Enter a name for your database (e.g., `mydatabase`).
- Server: Click Create new.
In the "Create SQL server" dialog:
- Server name: Enter a globally unique server name (e.g., `myazuresqlserver-unique`). The portal will check for availability.
- Location: Choose an Azure region close to you or your users.
- Admin login: Enter a username for the server administrator (e.g., `sqladmin`).
- Password: Enter a strong password and confirm it.
- Click OK.
Back on the "Create SQL database" page, under Workload environment, select Development for testing or Production for live applications. For this quickstart, Development is fine.
Under Compute + storage, click Configure database. For getting started, the default General Purpose tier with a suitable vCore count is recommended. You can choose a Serverless option for auto-scaling and cost-effectiveness.
Click Apply.
Review the other tabs (Networking, Security, etc.) as needed. For this guide, defaults are sufficient. Click Review + create, then Create.
It will take a few minutes for the server and database to be provisioned. You'll see a notification when it's complete.
Step 2: Configure Firewall Rules
By default, Azure SQL Database is protected by a firewall. You need to allow your local IP address to connect.
Navigate to your newly created Azure SQL server resource in the Azure portal.
In the left-hand menu, under Security, click Firewalls and virtual networks.
Click the Add client IP button. This automatically adds your current public IP address to the allowed list.
You can optionally give this rule a name and specify a range of IP addresses. For a single machine, adding the client IP is usually sufficient.
Click Save.
Step 3: Connect to Your Database
Now that your database is created and accessible, let's connect to it using SQL Server Management Studio (SSMS).
Open SQL Server Management Studio (SSMS).
In the Connect to Server dialog:
- Server name: Enter the fully qualified server name. You can find this on the Overview page of your SQL server in the Azure portal (it will look something like `myazuresqlserver-unique.database.windows.net`).
- Authentication: Select SQL Server Authentication.
- Login: Enter the admin login you created earlier (e.g., `sqladmin`).
- Password: Enter the password you set for the admin login.
Click Connect.
If the connection is successful, you'll see your Azure SQL server in the Object Explorer. Expand the Databases folder to see your newly created database (e.g., `mydatabase`). You can now run T-SQL queries against your database.
- Explore T-SQL queries to interact with your data.
- Learn about migrating existing databases.
- Discover various tutorials for common scenarios.
Troubleshooting Common Connection Issues
Connection timed out
This usually means the firewall is blocking your connection. Double-check that your client IP is added to the server's firewall rules in the Azure portal.
Login failed for user '...'
Verify that you are using the correct username and password. Ensure you are using SQL Server Authentication and not Windows Authentication.