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:
- Define what SQL does for you and explain how it applies to SQL Server 7
- Describe the basic features of Transact-SQL, Microsoft's version of SQL
- Explain how SQL Server 7 processes queries
- Use variables to write a Transact-SQL statement
- Use control-of-flow logic in Transact-SQL statements
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.