SQL Practice Logo

SQLPractice Online

SQL Server Features Deep Dive: Functions

Module: Database-Specific Features

SQL Server T-SQL syntax: (1) TOP: SELECT TOP n instead of LIMIT n. (2) IDENTITY: INT IDENTITY(1,1) instead of AUTO_INCREMENT. (3) Variables: DECLARE @var INT; SET @var = value. (4) Control flow: IF condition BEGIN ... END, WHILE condition BEGIN ... END. (5) Window functions: ROW_NUMBER() OVER (ORDER BY col), PARTITION BY for grouping. (6) OFFSET/FETCH: OFFSET n ROWS FETCH NEXT m ROWS ONLY (SQL Server 2012+). (7) Temporal: FOR SYSTEM_TIME AS OF date, FOR SYSTEM_TIME ALL.

TOP: SELECT TOP n instead of LIMIT n, use with ORDER BY

IDENTITY: INT IDENTITY(1,1) instead of AUTO_INCREMENT, seed and increment

Variables: DECLARE @var type; SET @var = value, use @ prefix

Control flow: IF condition BEGIN ... END, WHILE loop, no THEN keyword

Window functions: ROW_NUMBER() OVER (ORDER BY col), PARTITION BY for grouping

OFFSET/FETCH: OFFSET n ROWS FETCH NEXT m ROWS ONLY (SQL Server 2012+)

Temporal: FOR SYSTEM_TIME AS OF date, FOR SYSTEM_TIME ALL for history

T-SQL, TOP, IDENTITY, window functions, columnstore, temporal tables, Always On

Standard SQL, LIMIT, SERIAL, window functions, no columnstore, no temporal (use triggers)

LIMIT, AUTO_INCREMENT, window functions (8.0+), no columnstore, no temporal

PL/SQL, ROWNUM/FETCH, SEQUENCE, window functions, no columnstore, Flashback (similar to temporal)

Core references in this topic include WHERE, =, <, >, <=, >=. Learn what each one does, when to use it, and the execution or engine rules that matter.

WHERE

Filters rows before projection and sorting. It decides which rows continue through the query pipeline.

SELECT ... FROM table WHERE condition;

Most performance issues start with a weak WHERE clause or a missing supporting index.

=

Returns rows where the left and right values are exactly equal.

column = value

Use with exact matches. Do not use = NULL.

<, >, <=, >=

Range comparison operators for less-than, greater-than, and inclusive boundary checks.

salary >= 80000

BETWEEN

Checks whether a value falls inside an inclusive lower/upper range.

order_total BETWEEN 100 AND 500

ANY / ALL

Compares one value against every or at least one value from a subquery result.

salary > ALL (SELECT salary FROM interns)

EXTRACT

Pulls a single date/time component such as year, month, day, or hour from a temporal value.

EXTRACT(YEAR FROM order_date)

PRIMARY KEY

Uniquely identifies each row and implicitly requires NOT NULL.

customer_id INT PRIMARY KEY

COUNT

Counts rows or non-NULL values depending on the argument.

COUNT(*)

SUM