Learn SQL Server: practise standard SQL and understand T-SQL

Microsoft SQL Server speaks Transact-SQL, or T-SQL. At its core it is the SQL this course teaches, plus a few habits of its own such as TOP, joining text with a plus sign and its own date functions. This page walks through them with examples and covers the tools, the free editions and a quick setup guide.

In short: SQL Server is Microsoft’s database system, and its SQL dialect is called T-SQL. SELECT, WHERE, JOIN, GROUP BY, CASE and COALESCE look the same as here. The main differences are TOP (3) instead of LIMIT 3, joining text with +, date functions such as GETDATE() and DATEADD(), automatic IDs with IDENTITY, and shortcuts like ISNULL and IIF. Two editions cost nothing and are fine for learning: Express and Developer.

What is SQL Server?

SQL Server is a relational database management system from Microsoft. You query it in Transact-SQL (T-SQL): standard SQL plus Microsoft additions such as TOP, variables that start with @ and functions like ISNULL. The server runs on Windows and, since SQL Server 2017, on Linux too (Red Hat Enterprise Linux and Ubuntu, for example), as well as in containers. In Microsoft’s cloud there is Azure SQL Database, whose database engine Microsoft says is built on the same code base.

Microsoft sells several editions. Enterprise and Standard are paid. Express is free and, in Microsoft’s words, ideal for learning and for small desktop and server applications; in SQL Server 2025 a single database can grow to 50 GB. The Developer editions are free as well and include every feature of Enterprise or Standard, but they are licensed for development and testing only, never for production.

Why this course works for SQL Server

Our exercises run on SQLite in your browser. The fundamentals (SELECT, WHERE, JOIN, GROUP BY, HAVING, CASE, subqueries, CTEs with WITH and window functions) are written the same way in SQL Server. Once you know the standard forms, only a handful of spots need rethinking when you switch, and they are all covered below. For SQL Server, MySQL, PostgreSQL and SQLite side by side, see MySQL vs PostgreSQL vs SQL Server. When you show the model solution in an exercise, a button above it switches it to the SQL Server version.

Try it now

The dashboard needs the three most recent orders. In the practice database you finish the query with LIMIT 3. The SQL Server version of the same query is right below the exercise.

Task The dashboard should show the three most recent orders. Show order_id, order_date and status for those three orders, newest first.

orders 18 rows, 5 columns
order_idcustomer_idorder_datestatusemployee_id
100112026-01-08delivered3
100242026-01-12delivered4
100332026-01-20delivered3
100472026-02-03delivered4
100522026-02-11cancelled8
100612026-02-25delivered3
1007102026-03-04delivered2
100852026-03-17delivered4
100982026-03-30delivered3
101062026-04-07delivered8
1011122026-04-22delivered4
101232026-05-06delivered3
101392026-05-19cancelled8
101472026-06-02shipped4
101512026-06-10shipped3
1016112026-06-12openNULL
101742026-06-13openNULL
1018102026-06-14openNULL

Where T-SQL differs

TOP instead of LIMIT

-- SQL Server
SELECT TOP (3) order_id, order_date, status
FROM orders
ORDER BY order_date DESC;

-- practice database, MySQL, PostgreSQL
SELECT order_id, order_date, status
FROM orders
ORDER BY order_date DESC
LIMIT 3;
order_idorder_datestatus
10182026-06-14open
10172026-06-13open
10162026-06-12open

TOP comes straight after SELECT. Microsoft recommends always putting the number in parentheses and always pairing TOP with ORDER BY in a SELECT; without a sort order you get whichever rows come first. WITH TIES adds any rows that tie with the last one. For paging through results, Microsoft points you to OFFSET 0 ROWS FETCH NEXT 3 ROWS ONLY after ORDER BY. Type TOP 3 into an exercise and it reminds you: “TOP only exists in SQL Server. Here (as in MySQL and PostgreSQL) you limit rows with LIMIT at the end”.

Joining text with +

T-SQL joins strings with +: last_name + ', ' + first_name. If one part is NULL, the result is typically NULL as well; the session setting CONCAT_NULL_YIELDS_NULL controls this. CONCAT(), on the other hand, treats NULL as an empty string and needs at least two arguments. SQL Server 2025 also adds the standard || operator, which older versions lack. In our practice database, + does arithmetic and turns text into 0. There is no error, just a wrong answer, so the exercise says “Columns and row count match, but not every value.” Use || or CONCAT here.

Dates: GETDATE, DATEADD and FORMAT

SELECT GETDATE();                         -- now, as datetime
SELECT CONVERT(date, GETDATE());          -- today's date only
SELECT DATEADD(day, 7, order_date) FROM orders;
SELECT DATEADD(month, 1, '2026-01-31');   -- 2026-02-28 00:00:00.000
SELECT FORMAT(order_date, 'yyyy-MM') AS order_month FROM orders;

DATEADD takes the date part first (day, month, year), then the number, then the date. If the target month is shorter, it lands on that month’s last day. FORMAT uses .NET format patterns, which is why the month is a capital MM; it also takes an optional culture such as 'en-US' or 'en-gb'. In the practice database the equivalents are date(order_date, '+7 days') and strftime('%Y-%m', order_date).

Automatic IDs: IDENTITY

CREATE TABLE categories (
  category_id INT IDENTITY(1, 1) PRIMARY KEY,
  name NVARCHAR(50) NOT NULL
);
INSERT INTO categories (name) VALUES ('Paper');

IDENTITY(1, 1) means start at 1 and count up by 1. Worth knowing: the numbers are not guaranteed to be gapless. After a server restart or a rolled-back INSERT some values can be skipped, and used values are never handed out again.

ISNULL and IIF: handy shortcuts

ISNULL(phone, 'no number') replaces NULL with a value, and Microsoft describes IIF(stock = 0, 'sold out', 'in stock') as a shorthand for CASE. Both exist only in SQL Server. One trap with ISNULL: the result takes the data type of the first argument, so a longer replacement text can be cut off. COALESCE and CASE run everywhere, which is why the exercises below use them.

Case sensitivity depends on the collation

Whether 'boston' = 'Boston' is true depends on the collation. A name ending in _CI means case-insensitive, _CS case-sensitive. During setup, SQL Server picks the default from the Windows locale: SQL_Latin1_General_CP1_CI_AS for English (United States) and Latin1_General_CI_AS for English (United Kingdom). Unless someone chose otherwise, SQL Server therefore compares text without regard to case, while our practice database is exact with =.

Square brackets, and what GO means

Names with spaces or reserved words go in square brackets, [Order Date], or in double quotes. Scripts often contain GO on a line of its own. It is not a T-SQL statement but a batch separator understood by SSMS and sqlcmd: everything before it is sent to the server as one batch, and variables only live until the next GO.

SSMS, VS Code and installation

  • SQL Server Management Studio (SSMS): the classic tool for managing and querying SQL Server. The current release, SSMS 22, runs on 64-bit Windows (Windows 11 and Windows Server 2019 to 2025) and installs through the Visual Studio Installer.
  • Visual Studio Code with the MSSQL extension: runs on Windows, macOS and Linux. Microsoft recommends it as the replacement for Azure Data Studio, which was retired on 28 February 2026.
  • sqlcmd: the command-line tool, included in every edition.
  • Installing the server: download Express or Developer from Microsoft. On Linux there are packages for Red Hat and Ubuntu, plus container images in the Microsoft Container Registry.

Check your SQL Server version

SELECT @@VERSION;

This returns one line of text with the version, build date, edition and operating system, starting with something like “Microsoft SQL Server 2025 (RTM)”. For individual values, use the SERVERPROPERTY function. Microsoft notes that version numbers of SQL Server and Azure SQL Database cannot be compared with each other.

Another exercise: rewrite IIF

A colleague wrote this query for SQL Server using IIF. Rebuild it with CASE and it will run on any database.

Task A colleague wrote this query for SQL Server: SELECT first_name, last_name, IIF(salary >= 54000, 'high', IIF(salary >= 42000, 'medium', 'low')) AS pay_band FROM employees WHERE salary IS NOT NULL ORDER BY last_name; The company wants to run it on PostgreSQL and MySQL as well, but neither has IIF. Rewrite it so it runs on all four databases, with a single CASE instead of two nested IIFs. Same result: columns first_name, last_name and pay_band, sorted by last_name.

employees 10 rows, 7 columns
employee_idfirst_namelast_namedepartmentsalaryhire_datemanager_id
1KarenMitchellManagement936002018-01-02NULL
2TomBradleySales624002019-04-011
3JuliaReyesSales468002021-06-152
4MarcusAllenSales492002020-09-012
5SarahLongWarehouse396002022-02-011
6FelixTurnerWarehouse354002024-03-185
7NinaCooperAccounting528002019-10-011
8DavidRossCustomer service384002023-05-022
9LauraHughesCustomer serviceNULL2025-09-012
10PaulWardAccounting432002022-11-147

And one with COALESCE instead of ISNULL

In SQL Server you might reach for ISNULL. The exercise asks for COALESCE, which works the same in all four systems; ISNULL gets “ISNULL() does not exist in this practice database (SQLite)” with a pointer to COALESCE.

Task Sales wants a phone list: show the name and phone of every customer. Where no number is on file, the list should say no number instead of leaving the cell blank.

customers 12 rows, 7 columns
customer_idnamecitycountrycustomer_sincesegmentphone
1Harbor Fremont PartnersBostonUSA2021-03-15Business617-555-0142
2Emily CarterChicagoUSA2022-07-01ConsumerNULL
3Riverside County OfficeRiversideUSA2020-11-20Government951-555-0110
4Raj PatelLeedsUK2023-01-09Consumer0113 496 0123
5Lakeview Hotel LtdManchesterUK2022-04-18Business0161 496 0456
6Olivia BrooksAustinUSA2024-02-27ConsumerNULL
7Greene & Shaw LLPLondonUK2021-09-05Business020 7946 0321
8Maple Grove High SchoolAustinUSA2023-08-14School512-555-0187
9Chloe EvansBostonUSA2025-05-30Consumer617-555-0199
10Northline Printing CoTorontoCanada2020-06-12Business416-555-0133
11Daniel KimSeattleUSA2024-10-03ConsumerNULL
12Westbrook Dental ClinicChicagoUSA2022-12-01Business312-555-0164

The lessons that matter most for SQL Server

FAQ

Is SQL Server free?

Two editions are. Express, which Microsoft describes as suitable for development and production of smaller applications, and Developer, which you may only use for development and testing. Standard and Enterprise require paid licences.

Can I run SQL Server on a Mac?

The server itself is available for Windows, for Linux and as a Linux container image. SSMS runs on Windows only; on macOS you work with Visual Studio Code and the MSSQL extension. You need none of this for the course, because the exercises run in your browser.

How do I check which version of SQL Server I have?

Run SELECT @@VERSION; in SSMS, VS Code or sqlcmd. The answer gives version, edition and operating system in one line of text.

What happened to Azure Data Studio?

Microsoft retired Azure Data Studio on 28 February 2026, and it no longer receives updates. The recommended replacement is Visual Studio Code with the MSSQL extension, with SSMS for administration tasks.

Do I need to know every T-SQL quirk?

No. The ones that matter day to day are TOP, joining text, the date functions and the ISNULL and IIF shortcuts. Look up the rest when you need it; the core stays standard SQL.

Sources: Microsoft Learn on learn.microsoft.com (TOP, + (String concatenation), || (String concatenation), CONCAT, GETDATE, DATEADD, FORMAT, IDENTITY (Property), ISNULL, IIF, Collation and Unicode Support, Database Identifiers, GO, @@VERSION, Editions and Supported Features of SQL Server 2025, What is SQL Server on Linux?, Install SSMS, SSMS System Requirements, What's Happening with Azure Data Studio), SQL Server downloads page on microsoft.com.

Next up: the first lesson

The course starts with your first query and takes you through JOIN, GROUP BY and window functions. With the differences on this page, everything carries over to SQL Server.

Start with the basics

Write to us

Choose language

Select your preferred language