Introduction to SQL

previous next


SQL is a standard computer language for accessing and manipulating databases.


What is SQL?


SQL is a Standard - BUT....

SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database systems. SQL statements are used to retrieve and update data in a database. SQL works with database programs like MySQL, Oracle, MS SQL Server, Microsoft Access, MSDE, DB2, Sybase, Postgres, Informix , etc.

Unfortunately, there are many different versions of the SQL language, but to be in compliance with the ANSI standard, they must support the same major keywords in a similar manner (such as SELECT, UPDATE, DELETE, INSERT, WHERE, and others).

Note: Most of the SQL database programs also have their own proprietary extensions in addition to the SQL standard!


SQL Database Tables

A database most often contains one or more tables. Each table is identified by a name (e.g. "Books" or "Authors"). Tables contain records (rows) with data.

Below is an example of a table called "Books":

Title

Author

Publisher

Year

الدورة الدموية

إبن النفيس

دار العلم

1650

Java 2

L. Johnston

Fast Press

2002

Linux and Unix

J. Sam

Fast Press

2004

Linux Distributions

J. Sam

Fast Press

2003

Operating Systems

M. Stone

Coriolis

2005

 The table above contains three records (one for each book) and four columns (Title, Author, Publisher, and Year).


SQL Queries

With SQL, we can query a database and have a result set returned.

A query like this:

SELECT Title, Author FROM Books;

Gives a result set like this:

Title

Author

الدورة الدموية

إبن النفيس

Java 2

L. Johnston

Linux and Unix

J. Sam

Linux Distributions

J. Sam

Operating Systems

M. Stone

 Note: Some database systems require a semicolon at the end of the SQL statement.


SQL Data Manipulation Language (DML)

SQL (Structured Query Language) is a syntax for executing queries. But the SQL language also includes a syntax to update, insert, and delete records.

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


SQL Data Definition Language (DDL)

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: 


Test your SQL Skills

To test your SQL skills click here.


previous next