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_id | customer_id | order_date | status | employee_id |
|---|---|---|---|---|
| 1001 | 1 | 2026-01-08 | delivered | 3 |
| 1002 | 4 | 2026-01-12 | delivered | 4 |
| 1003 | 3 | 2026-01-20 | delivered | 3 |
| 1004 | 7 | 2026-02-03 | delivered | 4 |
| 1005 | 2 | 2026-02-11 | cancelled | 8 |
| 1006 | 1 | 2026-02-25 | delivered | 3 |
| 1007 | 10 | 2026-03-04 | delivered | 2 |
| 1008 | 5 | 2026-03-17 | delivered | 4 |
| 1009 | 8 | 2026-03-30 | delivered | 3 |
| 1010 | 6 | 2026-04-07 | delivered | 8 |
| 1011 | 12 | 2026-04-22 | delivered | 4 |
| 1012 | 3 | 2026-05-06 | delivered | 3 |
| 1013 | 9 | 2026-05-19 | cancelled | 8 |
| 1014 | 7 | 2026-06-02 | shipped | 4 |
| 1015 | 1 | 2026-06-10 | shipped | 3 |
| 1016 | 11 | 2026-06-12 | open | NULL |
| 1017 | 4 | 2026-06-13 | open | NULL |
| 1018 | 10 | 2026-06-14 | open | NULL |
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_id | order_date | status |
|---|---|---|
| 1018 | 2026-06-14 | open |
| 1017 | 2026-06-13 | open |
| 1016 | 2026-06-12 | open |
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_id | first_name | last_name | department | salary | hire_date | manager_id |
|---|---|---|---|---|---|---|
| 1 | Karen | Mitchell | Management | 93600 | 2018-01-02 | NULL |
| 2 | Tom | Bradley | Sales | 62400 | 2019-04-01 | 1 |
| 3 | Julia | Reyes | Sales | 46800 | 2021-06-15 | 2 |
| 4 | Marcus | Allen | Sales | 49200 | 2020-09-01 | 2 |
| 5 | Sarah | Long | Warehouse | 39600 | 2022-02-01 | 1 |
| 6 | Felix | Turner | Warehouse | 35400 | 2024-03-18 | 5 |
| 7 | Nina | Cooper | Accounting | 52800 | 2019-10-01 | 1 |
| 8 | David | Ross | Customer service | 38400 | 2023-05-02 | 2 |
| 9 | Laura | Hughes | Customer service | NULL | 2025-09-01 | 2 |
| 10 | Paul | Ward | Accounting | 43200 | 2022-11-14 | 7 |
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_id | name | city | country | customer_since | segment | phone |
|---|---|---|---|---|---|---|
| 1 | Harbor Fremont Partners | Boston | USA | 2021-03-15 | Business | 617-555-0142 |
| 2 | Emily Carter | Chicago | USA | 2022-07-01 | Consumer | NULL |
| 3 | Riverside County Office | Riverside | USA | 2020-11-20 | Government | 951-555-0110 |
| 4 | Raj Patel | Leeds | UK | 2023-01-09 | Consumer | 0113 496 0123 |
| 5 | Lakeview Hotel Ltd | Manchester | UK | 2022-04-18 | Business | 0161 496 0456 |
| 6 | Olivia Brooks | Austin | USA | 2024-02-27 | Consumer | NULL |
| 7 | Greene & Shaw LLP | London | UK | 2021-09-05 | Business | 020 7946 0321 |
| 8 | Maple Grove High School | Austin | USA | 2023-08-14 | School | 512-555-0187 |
| 9 | Chloe Evans | Boston | USA | 2025-05-30 | Consumer | 617-555-0199 |
| 10 | Northline Printing Co | Toronto | Canada | 2020-06-12 | Business | 416-555-0133 |
| 11 | Daniel Kim | Seattle | USA | 2024-10-03 | Consumer | NULL |
| 12 | Westbrook Dental Clinic | Chicago | USA | 2022-12-01 | Business | 312-555-0164 |
The lessons that matter most for SQL Server
- ORDER BY and LIMIT: sorting is identical; instead of LIMIT you write TOP or OFFSET … FETCH.
- CASE WHEN and NULL and COALESCE: the standard forms behind IIF and ISNULL.
- String functions: CONCAT is the safe choice when parts may be empty.
- Date functions: same approach; in T-SQL the names are DATEADD, FORMAT and GETDATE.
- JOIN, GROUP BY and window functions: the reporting toolkit, written the same way in T-SQL.
- CREATE TABLE, primary and foreign keys and transactions: for when you build tables and change data in SQL Server yourself.
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.