SQL tutorial of w3resource is a comprehensive tutorial to learn SQL. We have followed SQL:2003 standard of ANSI. There are hundreds of examples given in this tutorial. Output are shown with Oracle 10G. Often outputs are followed by pictorial presentation and explanation for better understanding. You will hardly find a vendor neutral SQL tutorial covering SQL in such great detail.
What is SQL?
SQL stands for Structured Query Language and it is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database systems. It is used for managing data in relational database management system which stores data in the form of tables and relationship between data is also stored in the form of tables. SQL statements are used to retrieve and update data in a database. SQL works with database programs like DB2, Oracle, SQL Server, Sybase, MS Access, etc. There are many different versions of the SQL language, but to be in compliance with the ANSI standard, they support the major keyword such as SELECT, UPDATE, DELETE, INSERT, WHERE, and others. Following picture shows the communicating with an RDBMS using SQL.
History of SQL
In June 1970 Dr. E. F. Codd published the paper, "A Relational Model of Data for Large Shared Data Banks" in the Association of Computer Machinery (ACM) journal. Codd's model is now accepted as the definitive model for relational database management systems (RDBMS). Using Codd's model the language, Structured English Query Language (SEQUEL) was developed by IBM Corporation in San Jose Research Center. The language was first called SEQUEL but Official pronunciation of SQL is ESS QUE ELL. In 1979 Oracle introduced the first commercially available implementation of SQL. Today, SQL is accepted as the standard RDBMS language. Later other players join in the race. Here is the year wise development history :
– 1970 E.F. Codd publishes Definition of Relational Model
– 1975 Initial version of SQL Implemented (D. Chamberlin)
– IBM experimental version: System R (1977) w/revised SQL
– IBM commercial versions: SQL/DS and DB2 (early 1980s)
– Oracle introduces commercial version before IBM's SQL/DS
– INGRES 1981 & 85
– ShareBase 1982 & 86
– Data General (1984)
– Sybase (1986)
– by 1992 over 100 SQL products
SQL Standard Revisions
– SEQUEL/Original SQL - 1974
– SQL/86 - Ratification and acceptance of a formal SQL standard by ANSI (American National Standards Institute) and ISO (International Standards Organization).
– SQL/92 - Major revision (ISO 9075), Entry Level SQL-92 adopted as FIPS 127-2.
– SQL/99 - Added regular expression matching, recursive queries (e.g. transitive closure), triggers, support for procedural and control-of-flow statements, non-scalar types, and some object-oriented features (e.g. structured types).
– SQL/2003 - Introduced XML-related features (SQL/XML), Window functions, Auto generation.
– SQL/2006 - Lots of XML Support for XQuery, an XML-SQL interface standard.
– SQL/2008 - Adds INSTEAD OF triggers, TRUNCATE statement.
Constructs of SQL
Here is list of the key elements of SQL along with a brief description :
Queries : Retrives data against some criteria.
Statements : Controls transactions, program flow, connections, sessions, or diagnostics.
Clauses : Components of Queries and Statements.
Expressions : Combination of symbols and operators and key part of the SQL statements.
Predicates : Specifies conditions.
Some Key terms of SQL 2003
To know the key terms of SQL 2003, you should know the statement classes of both SQL 92 AND SQL 2003, since both are used to refer SQL features and statements.
In SQL 92, SQL statements are grouped into following categories :
The Data Manipulation Language (DML) is the subset of SQL which is used to add, update and delete data.
The Data Definition Language (DDL) is used to manage table and index structure. CREATE, ALTER, RENAME, DROP and TRUNCATE statements are to name a few data definition elements.
The Data Control Language (DCL) is used to set permissions to users and groups of users whether they can access and manipulate data.
A transaction contains number of SQL statements. After the transaction begins, all of the SQL statements are executed and at the end of the transaction, permanent changes are made in the associated tables.
Using a stored procedure, a method is created which contains source code for performing repetitive tasks.
In SQL 2003 statements are grouped in seven categories which are called classes. See the following table :
|SQL data statements||SELECT, INSERT, UPDATE, DELETE|
|SQL connection statements||CONNECT, DISCONNECT|
|SQL schema statements||ALTER, CREATE, DROP|
|SQL control statements||CALL, RETURN|
|SQL diagnostic statements||GET DIAGNOSTICS|
|SQL session statements||SET CONSTRAINT|
|SQL transaction statements||COMMIT, ROLLBACK|
PL-SQL, TSQL and PL/pgSQL
PL/SQL - Procedural Language/Structured Query Language ( PL/SQL) is Oracle Corporation's procedural extension language for SQL and the Oracle relational database.
TSQL - Transact-SQL (T-SQL) is Microsoft's and Sybase's proprietary extension to SQL.
PL/pgSQL - Procedural Language/PostgreSQL(PL/pgSQL) is a procedural programming language supported by the PostgreSQL.
What you will learn
In w3resource SQL tutorials, we have covered SQL 2003 standard in detail. Following is a list of the features we have included in our tutorials :
1. A simple but thorough description.
2. SQL Syntax.
3. Description of the Parameters used in the SQL command.
4. Sample table with data.
5. SQL command.
6. Explanation of the SQL command.
7. Output of the SQL command.
The programming language trends
photo credit: Tim Morgan. Photo is used under creative Common License.