SQL

Structured Query Language (SQL) (pronounced S-Q-L; historically "sequel")Beaulieu, Alan (April 2009). Mary E Treseler (ed.). Learning SQL (2nd ed.). Sebastopol, CA, USA: O'Reilly. ISBN 978-0-596-52083-0"Oral history interview with Donald D. Chamberlin" - Chamberlin, Donald D.; Frana, Philip L.; from University Digital Conservancy. (2001-10-03) is a domain-specific language used to manage data, especially in a relational database management system (RDBMS). It is particularly useful in handling structured data, such as data incorporating relations among entities and variables.
Introduced in the 1970s, SQL offered two main advantages over older read–write APIs such as ISAM or VSAM. Firstly, it introduced the concept of accessing many records with one single command. Secondly, it eliminates the need to specify how to reach a record, i.e., with or without an index.
==Syntax==
The SQL language is subdivided into several language elements, including:
*Clauses, which are constituent components of statements and queries. In some cases, these clauses 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), which is either true, false, or unknown, or boolean truth values and 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.
*Statements, which may have a persistent effect on schemata and data, or may 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.
*Insignificant whitespace is generally ignored in SQL statements and queries, making it easier to format SQL code for readability.
==Examples==
===Table===
Assuming the table below is the standard atomic weight and temperature of stable halogens. The table is named HALOGENTABLE
 HALOGENTABLE
Halogen 	AtomicWeight	MeltingPointByCelsius
Fluoride	18.998 	−219.62
Chloride	35.446 	−101.5
Bromine 	79.904 	−7.3
Iodine 	126.904 	113.7
Here is the syntax of selection
SELECT column1, column2, ...
FROM table_name;
To list all halogens only by MeltingPointByCelsius:
SELECT Halogen, MeltingPointByCelsius FROM HALOGENTABLE;
It will output the modified table:
 HALOGENTABLE
Halogen 	MeltingPointByCelsius
Fluoride	−219.62
Chloride	−101.5
Bromine 	−7.3
Iodine 	113.7
Using the keyword * will return all values of a table or a database.
===Creating a database===
To create a database:
CREATE DATABASE databasename;
To create a table in a database:
CREATE TABLE table_name (
 column1 datatype,
 column2 datatype,
 column3 datatype,
 ....
);
To add a key to a specific column of a table:
ADD column_name datatype;
To rename a specific column of a table:
RENAME COLUMN old_name to new_name;
To select or alter the table to modify anything: 
ALTER TABLE table_name
To delete or drop either a column, a database or a table:
DROP COLUMN column_name;
DROP TABLE table_name;
DROP DATABASE databasename;
Note: Be careful before dropping a database. Deleting a database will result in loss of complete information stored in the database!
===Conditions===
the syntax CHECK will determine whether the condition of a key is right. Here is the example of the SQL code with the keyword CHECK. If the condition is false, the key will not be added to the table.
For MySQL:
CREATE TABLE Persons (
 ID int NOT NULL,
 LastName varchar(255) NOT NULL,
 FirstName varchar(255),
 Age int,
 CHECK (Age>=18)
);
For SQL Server / Oracle / MS Access:
CREATE TABLE Persons (
 ID int NOT NULL,
 LastName varchar(255) NOT NULL,
 FirstName varchar(255),
 Age int CHECK (Age>=18)
);
Additionally, the condition can be added in the following code:
ALTER TABLE Persons
ADD CHECK (Age>=18);
==Alternatives==
There are multiple alternatives to SQL. A distinction should be made between alternatives to SQL as a language, and alternatives to the relational model itself. Below are proposed relational alternatives to the SQL language.
*.QL: object-oriented Datalog
*4D Query Language (4D QL)
*Datalog
*HTSQL: URL based query method
*IBM Business System 12 (IBM BS12): one of the first fully relational database management systems, introduced in 1982
*ISBL
*jOOQ: SQL implemented in Java as an internal domain-specific language
*Java Persistence Query Language (JPQL): The query language used by the Java Persistence API and Hibernate persistence library
*JavaScript: MongoDB implements its query language in a JavaScript API.
*LINQ: Runs SQL statements written like language constructs to query collections directly from inside .Net code
*Object Query Language
*QBE (Query By Example) created by Moshè Zloof, IBM 1977
*QUEL introduced in 1974 by the U.C. Berkeley Ingres project, closer to tuple relational calculus than SQL
*XQuery
==See Also==
*SQL in Wikipedia.
==References==
Category:Programming languages