Structured Query Language/Language Elements

From Wikibooks, open books for an open world
Jump to navigation Jump to search

SQL consists of statements that start with a keyword like SELECT, DELETE or CREATE and terminate with a semicolon. Their elements are case-insensitive except for fixed character string values like 'Mr. Brown'.

An example of a complete statement with several of its language elements.

  • Clauses: Statements are subdivided into clauses. The most popular one is the WHERE clause.
  • Predicates: Predicates specify conditions that can be evaluated to a boolean value. E.g.: a boolean comparison, BETWEEN, LIKE, IS NULL, IN, SOME/ANY, ALL, EXISTS.
  • Expressions: Expressions are numeric or string values by itself, or the result of arithmetic or concatenation operators, or the result of functions.
  • Object names: Names of database objects like tables, views, columns, functions.
  • Values: Numeric or string values.
  • Arithmetic operators: The plus sign, minus sign, asterisk and solidus (+, –, * and /) specify addition, subtraction, multiplication, and division.
  • Concatenation operator: The '||' sign specifies the concatenation of character strings.
  • Comparison operators: The equals operator, not equals operator, less than operator, greater than operator, less than or equals operator, greater than or equals operator ( =, <>, <, >, <=, >= ) compares values and expressions.
  • Boolean operators: AND, OR, NOT combines boolean values.