Archive

Archive for February 3, 2009

An introduction to SQL and its Components

February 3, 2009 Leave a comment

–>Introduction:

SQL or Structured Query Language is a language that provides an interface to relational database systems. The proper pronunciation of SQL is “ess cue ell,” and not “sequel” as is commonly heard. SQL was developed by IBM in the 1970s for use in System R, and is a de facto standard, as well as an ISO and ANSI standard. In common usage SQL also encompasses DML (Data Manipulation Language), for INSERTs, UPDATEs, DELETEs and DDL (Data Definition Language), used for creating and modifying tables and other database structures. The development of SQL is governed by standards. A major revision to the SQL standard was completed in 1992, called SQL2. SQL3 support object extensions and are (partially?) implemented in Oracle8 and 9i.

SQL (Structured Query Language) is a database computer language designed for managing data in relational database management systems (RDBMS). Its scope includes data query and update, schema creation and modification, and data access control. SQL was one of the first languages for Edgar F. Codd’s relational model in his influential 1970 paper, “A Relational Model of Data for Large Shared Data Banks” and became the most widely used language for relational databases.
 

–>Language elements:

The SQL language is sub-divided into several language elements, including:

1. Clauses which are in some cases optional, constituent components of statements and queries.

2. Expressions which can produce either scalar values or tables consisting of columns and rows of data.

3. Predicates which specify conditions that can be evaluated to SQL three-valued logic (3VL) Boolean truth values and which are used to limit the effects of statements and queries, or to change program flow.

4. Queries which retrieve data based on specific criteria.

5. Statements which may have a persistent effect on schemas and data, or which may control transactions, program flow, connections, sessions, or diagnostics.

6. 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.

7. Insignificant whitespace is generally ignored in SQL statements and queries, making it easier to format SQL code for readability.
 

–> Queries:

The most common operation in SQL is the query, which is performed with the declarative SELECT statement. SELECT retrieves data from one or more tables, or expressions. Standard SQL statements have no persistent effects on the database. Some non-standard implementations of SELECT can have persistent effects, such as the SELECT INTO syntax that exists in some databases.

Queries allow the user to describe desired data, leaving the database management system (DBMS) responsible for planning, optimizing, and performing the physical operations necessary to produce that result as it chooses.

A Query includes a list of columns to be included in the final result immediately following the SELECT keyword. An asterisk (“*”) can also be used to specify that the query should return all columns of the queried tables. SELECT is the most complex statement in SQL, with optional keywords and clauses that includes:

1. The FROM clause which indicates the table(s) from which data is to be retrieved. The FROM clause can include optional JOIN subclauses to specify the rules for joining tables.

2. The WHERE clause includes a comparison predicate, which restricts the rows returned by the query. The WHERE clause eliminates all rows from the result set for which the comparison predicate does not evaluate to True.

3. The GROUP BY clause is used to project rows having common values into a smaller set of rows. GROUP BY is often used in conjunction with SQL aggregation functions or to eliminate duplicate rows from a result set. The WHERE clause is applied before the GROUP BY clause.

4. The HAVING clause includes a predicate used to filter rows resulting from the GROUP BY clause. Because it acts on the results of the GROUP BY clause, aggregation functions can be used in the HAVING clause predicate.

5. The ORDER BY clause identifies which columns are used to sort the resulting data, and in which direction they should be sorted (options are ascending or descending). Without an ORDER BY clause, the order of rows returned by an SQL query is undefined.
 

–> A simple SELECT example:

SELECT *
FROM dbo.Book
WHERE price > 100.00
ORDER BY title;

 

–> With SQL you can:

– Create new Databases.
– Create new Tables in a database.
– Execute Queries against a database.
– Insert records in a database.
– Update records in a database.
– Delete records from a database.
– Retrieve data from a database.
– Create stored procedures in a database.
– Create views in a database.
– Set permissions on tables, procedures, and views.
 

For the complete history check my following [blog post].


Advertisement