SQL
Structured Query Language (SQL) is the most popular computer language used to create, modify and retrieve data from relational database management systems. The language has evolved beyond its original purpose to support object-relational database management systems. It is an ANSI/ISO standard.
SQL keywords
SQL keywords fall into several groups.
Data retrieval
The most frequently used operation in transactional databases is the data retrieval operation.
SELECT
is used to retrieve zero or more rows from one or more tables in a database. In most applications,SELECT
is the most commonly used DML command. In specifying aSELECT
query, the user specifies a description of the desired result set, but they do not specify what physical operations must be executed to produce that result set. Translating the query into an optimal query plan is left to the database system, more specifically to the query optimizer.- Commonly available keywords related to SELECT include:
FROM
is used to indicate which tables the data is to be taken from, as well as how the tables join to each other.WHERE
is used to identify which rows to be retrieved, or applied to GROUP BY.GROUP BY
is used to combine rows with related values into elements of a smaller set of rows.HAVING
is used to identify which rows, following a GROUP BY, are to be retrieved.ORDER BY
is used to identify which columns are used to sort the resulting data.
- Commonly available keywords related to SELECT include:
Data manipulation
First there are the standard Data Manipulation Language (DML) elements. DML is the subset of the language used to add, update and delete data.
INSERT
is used to add zero or more rows (formally tuples) to an existing table.UPDATE
is used to modify the values of a set of existing table rows.DELETE
removes zero or more existing rows from a table.
Data transaction
Transaction, if available, can be used to wrap around the DML operations.
BEGIN WORK
(orSTART TRANSACTION
, depending on SQL dialect) can be used to mark the start of a database transaction, which either completes completely or not at all.COMMIT
causes all data changes in a transaction to be made permanent.ROLLBACK
causes all data changes since the lastCOMMIT
orROLLBACK
to be discarded, so that the state of the data is "rolled back" to the way it was prior to those changes being requested.
COMMIT
and ROLLBACK
interact with areas such as transaction control and locking. Strictly, both terminate any open transaction and release any locks held on data. In the absence of a BEGIN WORK
or similar statement, the semantics of SQL are implementation-dependent.
Data definition
The second group of keywords is the Data Definition Language (DDL). DDL allows the user to define new tables and associated elements. Most commercial SQL databases have proprietary extensions in their DDL, which allow control over nonstandard features of the database system.
The most basic items of DDL are the CREATE
and DROP
commands.
CREATE
causes an object (a table, for example) to be created within the database.DROP
causes an existing object within the database to be deleted, usually irretrievably.
Some database systems also have an ALTER
command, which permits the user to modify an existing object in various ways -- for example, adding a column to an existing table.
Data control
The third group of SQL keywords is the Data Control Language (DCL). DCL handles the authorisation aspects of data and permits the user to control who has access to see or manipulate data within the database.
Its two main keywords are:
GRANT
- authorises a user to perform an operation or a set of operations.REVOKE
- removes or restricts the capability of a user to perform an operation or a set of operations.
Database systems using SQL
- List of relational database management systems
- List of object-relational database management systems
Criticisms of SQL
Technically, SQL is a declarative computer language for use with "relational databases". Theorists note that many of the original SQL features were inspired by, but in violation of, tuple calculus. Recent extensions to SQL achieved relational completeness, but have worsened the violations, as documented in The Third Manifesto.
In additional, there are also some criticisms about the practical use of SQL:
- The language syntax is rather complex (sometimes called "COBOL-like").
- It does not provide a standard way to split large commands into multiple smaller ones that reference each other by name (however some implementations allow for set-based functions to grant this functionality). This tends to result in "run-on SQL sentences"
- Implementations are inconsistent and, at times, incompatible between vendors.
- It is at times too difficult a syntax for DBAs (database administrators) to extend.
- Over-reliance on "NULLs", which some consider a flawed or over-used concept.
Alternatives to SQL
- IBM BS12
- Tutorial-D - A language by C. J. Date and colleagues
- TQL Proposal (Not to be confused with Luca Cardelli's TQL)
- Hibernate Query Language (HQL) - A Java-based tool that uses modified SQL
External links
- Secure Architecture for an SQL Server
- Database Debunking
- Oracle SQL FAQ
- History of SQL
- Comparison of different SQL implementations
- SQL related software archive
- The 1995 SQL Reunion: People, Projects, and Politics - System R