This quickstart shows how to use Azure Data Studio to connect to SQL Server, and then use Transact-SQL (T-SQL) statements to create the TutorialDB used in Azure Data Studio tutorials.
Prerequisites
To complete this quickstart, you need Azure Data Studio, and access to a SQL Server instance.
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 Login, but Windows Authentication is supported. Fill in the fields as follows:
Server Name: Enter server name here. For example, localhost.
Authentication Type: SQL Login
User name: User name for the SQL Server
Password: Password for the SQL Server
Database Name: <Default>
Server Group: <Default>
Create a database
The following steps create a database named TutorialDB:
Right-click on your server, localhost, and select New Query.
Paste the following snippet into the query window: and then select Run.
SQL
USEmaster;
GO
IF NOT EXISTS (
SELECTnameFROM sys.databases
WHEREname = N'TutorialDB'
)
CREATEDATABASE [TutorialDB];
GO
IF SERVERPROPERTY('ProductVersion') > '12'
ALTERDATABASE [TutorialDB] SET QUERY_STORE = ON;
GO
After the query completes, the new TutorialDB appears in the list of databases. If you don't see it, right-click the Databases node and select Refresh.
Create a table
The query editor is still connected to the master database, but we want to create a table in the TutorialDB database.
Change the connection context to TutorialDB:
Replace the text in the query window with the following snippet 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 column
[Name] NVARCHAR(50) NOTNULL,
[Location] NVARCHAR(50) NOTNULL,
[Email] NVARCHAR(50) NOTNULL
);
GO
After the query completes, the new Customers table appears in the list of tables. You might need to right-click the TutorialDB > Tables node and select Refresh.
Insert rows
Replace the text in the query window with the following snippet and select Run:
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.