Introduction to SQL
What is SQL
SQL stands for Structured Query Language. Structured Query Language is a standard computer language that is used to communicate with databases. In this Introduction to SQL, we will give a quick overview of the types of some of its everyday commands and uses.
When we use SQL to communicate with a database we send commands known as queries. There are many different types of query that can be used to perform different tasks such as retrieving data, adding new data, updating existing data, creating new structures to hold the data and much more. SQL enables us to perform very powerful database operations using quite simple queries.
One of the great advantages of SQL is that it is an ANSI standard (ANSI stands for American National Standards Institute) and this means that it can be used to query virtually all modern Relational Database Management Systems (RDMS) including Microsoft Access, Microsoft SQL Server, MSDE, Oracle, DB2, MySQL, SyBase, Informix, etc.
It is worth noting that different software manufacturers have added their own extensions to the SQL-92 ANSI standard to form their own 'versions' of SQL (Microsoft SQL Server uses T-SQL, Oracle call their version PL/SQL, etc). The vast majority of the standard SQL commands will, however, work on databases from the different software manufacturers.
Give me some examples of SQL in action
In order to show some simple examples of how SQL can be used in the real-world, we must first identify how data is stored in a database. Data is stored in tables made up of rows (records) and columns (fields). A simple example of a table that stores a shops product information can be seen below:
Some quick examples of how we might manipulate the data in the above table using SQL are given below so that you can see what SQL looks like. In subsequent articles in this series, we will look at the different commands in turn so that you can quickly get to grips to querying databases using SQL.
1) Retrieving data from the Name and UnitCost columns which has a Unit Cost greater than 8.
SELECT Name, UnitCost FROM Products WHERE UnitCost > 8
This would return the following resultset:
2) Updating the Blue Widget record so that there were only 15 left in stock:
UPDATE Products SET NumInStock = 15 WHERE ProductCode = 'W32'
3) Deleting the Basic Widget record:
DELETE FROM Products WHERE ProductCode = 'B55'
4) Adding a new product to the database
INSERT INTO Products (ProductCode, Name, UnitCost, NumInStock) VALUES ('N44', 'My New product', 15.00, 20)
The 4 examples above belong to a subset of SQL known as Data Manipulation Language (DML) and when learning SQL these are the types of statements that you will learn first. As you can see the SQL language is fairly self-describing and uses keywords taken from everyday use such as SELECT, DELETE, INSERT and UPDATE.
The subsequent articles in this series will introduce you to the most important commands for using SQL in the real world. The next article covers how to use the SELECT statement in SQL.