SQL Statement Structure | SQL Fundamentals | Teradata Vantage - SQL Statement Structure - Advanced SQL Engine - Teradata Database

SQL Fundamentals

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-28
dita:mapPath
uhe1592872955107.ditamap
dita:ditavalPath
uhe1592872955107.ditaval
dita:id
B035-1141
lifecycle
previous
Product Category
Teradata Vantageā„¢

Syntax

The following diagram indicates the basic structure of an SQL statement.

statement_keyword
  { expressions |
    functions |
    keywords |
    clauses |
    phrases
  } [[,]...] [;]
statement_keyword
The name of the statement.
expressions
Literals, name references, or operations using names and literals.
functions
The name of a function and its arguments, if any.
keywords
Special values introducing clauses or phrases or representing special objects, such as NULL. Most keywords are reserved words and cannot be used in names.
clauses
Subordinate statement qualifiers.
phrases
Data attribute phrases.
;
The Teradata SQL statement separator and request terminator.
The semicolon separates statements in a multistatement request and terminates a request when it is the last nonblank character on an input line in BTEQ.
The request terminator is required for a request defined in the body of a macro.

Typical SQL Statement

A typical SQL statement consists of a statement keyword, one or more column names, a database name, a table name, and one or more optional clauses introduced by keywords. For example, in the following single-statement request, the statement keyword is SELECT:

SELECT deptno, name, salary
FROM personnel.employee
WHERE deptno IN(100, 500)
ORDER BY deptno, name ;
The select list for this statement is made up of object names:
  • Deptno, name, and salary (the column names)
  • Personnel (the database name)
  • Employee (the table name)

The search condition, or WHERE clause, is introduced by the keyword WHERE.

WHERE deptno IN(100, 500)

The sort order, or ORDER BY, clause is introduced by the keywords ORDER BY.

ORDER BY deptno, name

Related Information

For more information about the elements that appear in an SQL statement:

For the distinction between statement and request, see SQL Statements and SQL Requests.