| title | Quickstart: Connect and query SQL Server using SQL Operations Studio (preview) | Microsoft Docs |
|---|---|
| description | This quickstart shows how to use SQL Operations Studio (preview) to connect to SQL Server and run a query |
| ms.custom | tools|sos |
| ms.date | 11/15/2017 |
| ms.prod | sql-non-specified |
| ms.reviewer | alayu; erickang; sstein |
| ms.suite | sql |
| ms.prod_service | sql-tools |
| ms.component | sos |
| ms.tgt_pltfrm | |
| ms.topic | quickstart |
| author | yualan |
| ms.author | alayu |
| manager | craigg |
| ms.workload | Inactive |
Quickstart: Connect and query SQL Server using [!INCLUDEname-sos]
This quickstart shows how to use [!INCLUDEname-sos] to connect to SQL Server, and then use Transact-SQL (T-SQL) statements to create the TutorialDB used in [!INCLUDEname-sos] tutorials.
To complete this quickstart, you need [!INCLUDEname-sos], and access to a SQL Server.
- [Install [!INCLUDEname-sos]](download.md).
If you don't have access to a SQL Server, select your platform from the following links (make sure you remember your SQL Login and Password!):
- Windows - Download SQL Server 2017 Developer Edition
- macOS - Download SQL Server 2017 on Docker
- Linux - Download SQL Server 2017 Developer Edition - You only need to follow the steps up to Create and Query Data.
-
Start [!INCLUDEname-sos].
-
The first time you run [!INCLUDEname-sos] the Connection dialog opens. If the Connection dialog doesn't open, click the New Connection icon in the SERVERS page:
-
This article uses SQL Login, but Windows Authentication is supported. Fill in the fields as follows:
- Server Name: localhost
- Authentication Type: SQL Login
- User name: User name for the SQL Server
- Password: Password for the SQL Server
- Database Name: leave this field blank
- Server Group: <Default>
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:
USE master GO IF NOT EXISTS ( SELECT name FROM sys.databases WHERE name = N'TutorialDB' ) CREATE DATABASE [TutorialDB] GO ALTER DATABASE [TutorialDB] SET QUERY_STORE=ON GO
-
To execute the query, click Run .
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.
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:
-
Paste the following snippet into the query window:
-- 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 DROP TABLE dbo.Customers GO -- Create the table in the specified schema CREATE TABLE dbo.Customers ( CustomerId INT NOT NULL PRIMARY KEY, -- primary key column Name [NVARCHAR](50) NOT NULL, Location [NVARCHAR](50) NOT NULL, Email [NVARCHAR](50) NOT NULL ); 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.
-
Paste the following snippet into the query window:
-- Insert rows into table 'Customers' INSERT INTO dbo.Customers ([CustomerId],[Name],[Location],[Email]) VALUES ( 1, N'Orlando', N'Australia', N''), ( 2, N'Keith', N'India', N'keith0@adventure-works.com'), ( 3, N'Donna', N'Germany', N'donna0@adventure-works.com'), ( 4, N'Janet', N'United States', N'janet1@adventure-works.com') GO
-
To execute the query, click Run.
-
Paste the following snippet into the query window:
-- Select rows from table 'Customers' SELECT * FROM dbo.Customers;
-
To execute the query, click Run.
Now that you've successfully connected to SQL Server and run a query, try out the Code editor tutorial.


