INTRODUCTION TO
SQL
SQL (Structured
Query Language) is a special
purpose programming language designed
for managing data held in a relational
database management system (RDBMS).
Originally based upon relational
algebra and tuple relational
calculus, SQL consists of a data
definition language and a data manipulation language. The scope
of SQL includes data insert, query, update
and delete schema creation and modification, and data access control. Although
SQL is often described as, and to a great extent is, a declarative
language (4GL), it also includes procedural elements.
SQL was one of the first commercial languages for Edgar F. Codd's relational
model, as described in his influential 1970 paper
"A Relational Model of Data for Large Shared Data Banks".Despite not
entirely adhering to the
relational model as described by Codd, it became the
most widely used database language.
SQL became a standard of the American
National Standards Institute (ANSI) in
1986, and of the International
Organization for Standards (ISO) in 1987. Since then, the standard has been
enhanced several times with added features. Despite these standards, code is
not completely portable among different database systems, which can lead to vendor lock-in. The different makers do not perfectly adhere to the
standard, for instance by adding extensions, and the standard itself is
sometimes ambiguous.
Language elements
The SQL language is subdivided into several language
elements, including:
·
Clauses, which are constituent components of statements
and queries. (In some cases, these are optional.)
·
Expressions, which can produce either scalar values, or tables consisting of columns and rows of data.
·
Predicates, which specify conditions that can be evaluated
to SQL three-valued
logic (3VL) (true/false/unknown) or Boolean truth
values and which are used to limit the effects of statements and
queries, or to change program flow.
·
Queries, which retrieve the data based on specific
criteria. This is an important element of SQL.
·
control
transactions, program flow, connections, sessions, or diagnostics.
·
SQL
statements also include the semicolon (";") statement terminator. Though not required
on every platform, it is defined as a standard part of the SQL grammar.
OPERATORS
|
Operator
|
Description
|
Example
|
|
=
|
Equal to
|
Author
= 'Alcott'
|
|
<> or !=
|
Not equal to
|
Dept
<> 'Sales'
|
|
>
|
Greater than
|
Hire_Date
> '2012-01-31'
|
|
<
|
Less than
|
Bonus
< 50000.00
|
|
>=
|
Greater than or equal
|
Dependents
>= 2
|
|
<=
|
Less than or equal
|
Rate
<= 0.05
|
|
BETWEEN
|
Between an inclusive range
|
Cost
BETWEEN 100.00 AND 500.00
|
|
LIKE
|
Match a character pattern
|
First_Name
LIKE 'Will%'
|
|
IN
|
Equal to one of multiple possible values
|
DeptCode
IN (101, 103, 209)
|
|
IS or IS NOT
|
Compare to null (missing data)
|
Address
IS NOT NULL
|
Table 1.3 Operators in SQL