SQL Database Creation · Module 6

Basic Transact-SQL Statement Elements

Lesson 1

Basic Elements of a Transact-SQL Statement

You should now have a pretty good understanding of what SQL Server 2022 is and of relational concepts. Now it's time to learn about Structured Query Language (SQL), the standard language used by all relational databases, including SQL Server 7.

Learning objectives

After completing this module, you'll be able to:
  1. Define what SQL does for you and explain how it applies to SQL Server 7
  2. Describe the basic features of Transact-SQL, Microsoft's version of SQL
  3. Explain how SQL Server 7 processes queries
  4. Use variables to write a Transact-SQL statement
  5. Use control-of-flow logic in Transact-SQL statements
In the next lesson, you'll learn what SQL is and what it does for you.

Basic elements of a Transact-SQL (T-SQL) statement in SQL Server 2025:

A T-SQL statement is an atomic unit of work that either fully succeeds or fails. It consists of:
  • Keywords / Reserved words — SELECT, FROM, WHERE, INSERT, UPDATE, CREATE, etc.
  • Identifiers — Names of objects (tables, columns, databases, schemas, variables prefixed with @).
  • Data types — Define data (e.g., int, varchar, datetime); influence results even when not written explicitly.
  • Constants (literals) — Fixed values such as 123, 'text', NULL, or dates.
  • Expressions — Combinations that evaluate to a single value (constants, columns, variables, functions, or nested expressions).
  • Operators — Arithmetic (+, *), comparison (=, >), logical (AND, OR), string, bitwise, etc.
  • Functions — Built-in or user-defined that return scalar or tabular results (e.g., SUM, GETDATE, CAST).
  • Clauses — Structured parts of statements (especially queries), such as SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY.
  • Comments — Non-executed text: -- (single-line) or /* */ (block).
  • Terminator — Optional semicolon (;); recommended and will become required in a future version.
These elements form all statement categories (DML, DDL, DCL, control-of-flow, etc.). The structure is unchanged in SQL Server 2025.