In this quickstart, you'll use Azure Data Studio to connect to an Azure SQL Database server. You'll then run Transact-SQL (T-SQL) statements to create and query the TutorialDB database, which is used in other Azure Data Studio tutorials.
Note
While Microsoft Entra ID is the new name for Azure Active Directory (Azure AD), to prevent disrupting existing environments, Azure AD still remains in some hardcoded elements such as UI fields, connection providers, error codes, and cmdlets. In this article, the two names are interchangeable.
Prerequisites
To complete this quickstart, you need Azure Data Studio, and an Azure SQL Database server.
If you don't have an Azure SQL server, complete one of the following Azure SQL Database quickstarts. Remember the fully qualified server name and sign in credentials for later steps:
Use Azure Data Studio to establish a connection to your Azure SQL Database server.
The first time you run Azure Data Studio the Welcome page should open. If you don't see the Welcome page, select Help > Welcome. Select New Connection to open the Connection pane:
This article uses SQL authentication, but Microsoft Entra authentication is supported for all SQL Server products and services. Fill in the following fields using the server name, user name, and password for your Azure SQL server:
Setting
Suggested value
Description
Server name
The fully qualified server name
Something like: servername.database.windows.net.
Authentication
SQL Login
This tutorial uses SQL Authentication.
User name
The server admin account user name
The user name from the account used to create the server.
Password (SQL Login)
The server admin account password
The password from the account used to create the server.
Save Password?
Yes or No
Select Yes if you don't want to enter the password each time.
Database name
leave blank
You're only connecting to the server here.
Server Group
Select <Default>
You can set this field to a specific server group you created.
Select Connect.
If your server doesn't have a firewall rule allowing Azure Data Studio to connect, the Create new firewall rule form opens. Complete the form to create a new firewall rule. For details, see Firewall rules.
After successfully connecting, your server opens in the SERVERS sidebar.
Create the tutorial database
The next sections create the TutorialDB database that's used in other Azure Data Studio tutorials.
Right-click on your Azure SQL server in the SERVERS sidebar and select New Query.
Paste this SQL into the query editor.
SQL
IF NOT EXISTS (
SELECTnameFROM sys.databases
WHEREname = N'TutorialDB'
)
CREATEDATABASE [TutorialDB]
GOALTERDATABASE [TutorialDB] SET QUERY_STORE=ONGO
From the toolbar, select Run. Notifications appear in the MESSAGES pane showing query progress.
Create a table
The query editor is connected to the master database, but we want to create a table in the TutorialDB database.
Connect to the TutorialDB database.
Create a Customers table.
Replace the previous query in the query editor with this one and select Run.
SQL
-- Create a new table called 'Customers' in schema 'dbo'-- Drop the table if it already exists
IF OBJECT_ID('dbo.Customers', 'U') IS NOT NULL
DROPTABLE dbo.Customers
GO-- Create the table in the specified schemaCREATETABLE dbo.Customers
(
CustomerId INTNOTNULL PRIMARY KEY, -- primary key columnName [NVARCHAR](50) NOTNULL,
Location [NVARCHAR](50) NOTNULL,
Email [NVARCHAR](50) NOTNULL
);
GO
Insert rows into the table
Replace the previous query with this one and select Run.
Replace the previous query with this one and select Run.
SQL
-- Select rows from table 'Customers'SELECT * FROM dbo.Customers;
The query results display:
Clean up resources
Later quickstart articles build upon the resources created here. If you plan to work through these articles, be sure not to delete these resources. Otherwise, in the Azure portal, delete the resources you no longer need. For details, see Clean up resources.
Next steps
Now that you've successfully connected to an Azure SQL database and run a query, try the Code editor tutorial.
Find out what makes Azure SQL Database a good choice for your relational database, how to create the database from the portal and connect with Azure Cloud Shell.
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.
Explains the connection parameters to connect to an instance of SQL Server with Azure Data Studio. Includes details about how to secure and encrypt connections.