Introduction to SQL


SQL is an ANSI standard language for accessing databases.


What is SQL?


SQL is a Standard

SQL is an ANSI (American National Standards Institute) standard for accessing database systems. SQL statements are used to retrieve and update data in a database.

SQL works with database programs like Access, DB2, Informix, Microsoft SQL Server, Oracle, Sybase, and many others (but unfortunately most of them also have their own proprietary extensions to the language).


Database Tables

Databases contain objects called Tables.

Records of data are stored in these tables. Tables are identified by names (like "Persons", "Orders", "Suppliers").

Tables contain Columns and Rows with data. Rows contain records (like one record for each person). Columns contain data (like First Name, Last Name, Address, and City).

Here is an example of  a Table called "Persons":

LastName FirstName Address City
Hansen Ola Timoteivn 10 Sandnes
Svendson Tove Borgvn 23 Sandnes
Pettersen Kari Storgt 20 Stavanger

LastName, FirstName, Address, and City are table Columns. The Rows contain 3 records about 3 persons.


SQL Queries

With SQL, we can Query a database and have a Result returned in a tabular form.

A Query like this:

SELECT LastName FROM Persons

Will give a Result like this:

LastName
Hansen
Svendson
Pettersen

Note: Some database systems require a semicolon at the end of the SQL statement. We don't use the semicolon in our tutorials.


SQL Data Manipulation

As the name suggests, SQL is a syntax for executing queries. But the SQL language also includes a syntax to update records, insert new records and delete existing records.

These query and update commands together form the Data Manipulation Language (DML) part of SQL: 


SQL Data Definition

The Data Definition Language (DDL) part of SQL permits database tables to be created or deleted. We can also define indexes (keys), specify links between tables, and impose constraints between database tables.

The most important DDL statements in SQL are: