| Lesson 2 | Executing queries |
| Objective | Describe how to execute your queries in SQL Server 2022. |
Most of this course focuses on designing and writing T-SQL queries. In practice, however, your query is not useful until you know how to execute it against a SQL Server instance, review the results, and iterate quickly.
In a modern environment, you will typically execute queries against:
The primary tool for interactive query execution is SQL Server Management Studio (SSMS), which can connect to all of these environments. You can also use Azure Data Studio, command-line tools, and application code, but SSMS is the best starting point for learning how to execute and analyze queries.
SQL Server Management Studio is installed separately from the SQL Server engine. The basic process is:
https://aka.ms/ssms).SSMS-Setup-*.exe file and accept the default installation options.After installation, launch SSMS from the Start menu, then connect to:
localhost, a server name, or an Azure SQL endpointOnce connected, you are ready to execute T-SQL queries against your chosen database.
The most common workflow in SSMS is to write and run queries in a Query Editor window. Here is the typical sequence:
USE DatabaseName; at the top of your script.SELECT, INSERT, UPDATE, or DELETE statement.
SELECT TOP (10) CustomerID, CompanyName
FROM Sales.Customers
ORDER BY CustomerID;
This basic pattern—connect, select a database, write T-SQL, execute, review—forms the foundation for all query work in SQL Server 2022.
SSMS allows you to execute multiple statements at once as a batch. Batches are important when you need to:
In a script, the GO keyword is interpreted by SSMS (not the SQL Server engine) as a batch separator:
USE SalesDB;
GO
DECLARE @MinAmount money = 100.00;
SELECT OrderID, OrderTotal
FROM Sales.Orders
WHERE OrderTotal >= @MinAmount;
GO
When you click Execute, SSMS sends each batch (the statements between GO lines)
to SQL Server separately, in sequence. Understanding how batches are segmented helps you reason about
variable scope and compilation boundaries.
While SSMS is the primary teaching tool in this course, you should be aware of other ways to execute queries in SQL Server 2022:
Regardless of the tool, the underlying process is the same: connect to the database engine, send T-SQL statements, and handle the results (or errors).
Executing queries is not just about getting the right answer—it is also about understanding how SQL Server produced that answer. Execution plans show how the Database Engine navigates tables, uses indexes, and joins data.
In SSMS, you can:
SET STATISTICS IO, SET STATISTICS TIME, or
SET SHOWPLAN_XML to output plan and performance data in text or XML form.In later modules you will examine execution plans in more detail, but for now it is enough to know that: SSMS lets you execute a query and immediately see how the engine processed it, which is essential for performance tuning.