Create and connect to Azure SQL Database using Azure portal
This quickstart guides you through the steps to create an Azure SQL Database using the Azure portal and then connect to it using SQL Server Management Studio (SSMS).
Prerequisites
- An Azure subscription. If you don't have one, create a free account.
- SQL Server Management Studio (SSMS) installed. If you don't have it, download it from the Microsoft Download Center.
Step 1: Create an Azure SQL Database
Follow these steps to create a new Azure SQL Database:
- Sign in to the Azure portal.
- In the Azure portal search bar, type SQL databases and select it.
- Click + Create.
- On the Basics tab:
- Subscription: Select your Azure subscription.
- Resource group: Select an existing resource group or create a new one by clicking Create new.
- Database name: Enter a unique name for your database (e.g.,
mydatabasequickstart). - Server:
- If you have an existing SQL server, select it from the dropdown.
- If you need to create a new server, click Create new. Provide a unique server name, choose a location, and set an administrator login and password.
- Workload environment: Select Production or Development.
- Compute + storage: Select a service tier and compute size. For this quickstart, the Basic tier is sufficient.
- Click Review + create and then Create.
Step 2: Connect to the Azure SQL Database using SSMS
Once your database is deployed, you can connect to it using SQL Server Management Studio (SSMS).
- In the Azure portal, navigate to your newly created Azure SQL database.
- On the database overview page, find and copy the Server name. It will look something like
yourservername.database.windows.net. - Open SQL Server Management Studio (SSMS).
- In the Connect to Server dialog:
- Server type: Select Database Engine.
- Server name: Paste the server name you copied from the Azure portal.
- Authentication: Select SQL Server Authentication.
- Login: Enter the administrator login name you created for your server.
- Password: Enter the password for your administrator login.
- Click Connect.
Step 3: Create a sample table and insert data
Now that you're connected, let's run some Transact-SQL (T-SQL) commands to create a table and insert some data.
-- Create a new table called 'Customers'
CREATE TABLE Customers (
CustomerID int IDENTITY(1,1) NOT NULL,
CustomerName nvarchar(50) NOT NULL,
ContactName nvarchar(50) NOT NULL,
City nvarchar(50)
);
-- Insert rows into the 'Customers' table
INSERT INTO Customers (CustomerName, ContactName, City) VALUES
('Cardinal', 'Tom B. Erichsen', 'Stavanger'),
('Acme Corporation', 'Ann Beebe', 'Salt Lake City'),
('The Shire', 'Frodo Baggins', 'Hobbiton');
-- Select all rows from the 'Customers' table
SELECT * FROM Customers;
Step 4: Query the data
In SSMS, execute the following query to retrieve the data you just inserted:
SELECT * FROM Customers;
You should see the three rows you inserted into the Customers table.
Next Steps
Congratulations! You have successfully created an Azure SQL Database, connected to it, and run some basic queries. Here are some next steps:
- Learn more about configuring firewall rules.
- Explore advanced database management tasks.
- Discover different connection methods to your Azure SQL Database.