Introduction to SQL

SQL is Behind All Modern Relational Databases

The Structured Query Language (SQL) is the language of databases. All modern relational databases, including Access, FileMaker Pro, Microsoft SQL Server and Oracle use SQL as their basic building block. In fact, it’s often the only way that you can interact with the database itself. All of the graphical user interfaces that provide data entry and manipulation functionality are nothing more than SQL translators.

They take the actions you perform graphically and convert them to SQL commands understood by the database.

SQL is Similar to English

At this point, you might be thinking that you’re not a programmer and learning a programming language is certainly not up your alley. Fortunately, at its core, SQL is a simple language. It has a limited number of commands, and those commands are very readable and are almost structured like English sentences.

Introducing Databases

To understand SQL, it’s important to have a basic understanding of how databases work. If you’re comfortable with terms like table, relation and query, feel free to plow right ahead! If not, you may wish to read the article Database Fundamentals before moving on.

Let’s look at an example. Suppose you have a simple database designed to keep the inventory for a convenience store. One of the tables in your database might contain the prices of the items on your shelves indexed by unique stock numbers that identify each item.

You’d probably give that table a simple name like “Prices.”

Perhaps you want to remove items from your store that are priced over $25, you would "query" the database for a list of all these items.This is where SQL comes in.

Your First SQL Query

Before we get into the SQL statement required to retrieve this information, let’s try phrasing our question in plain English.

We want to “select all stock numbers from the prices table where the price is over $25.” That’s a pretty simple request when expressed in plain English, and it’s almost as simple in SQL. Here’s the corresponding SQL statement:

SELECT StockNumber
FROM Prices
WHERE Price > 5

It’s as simple as that! If you read the statement above out loud, you’ll find that it’s extremely similar to the English question we posed in the last paragraph.

Interpreting SQL Statements

Now let’s try another example. This time, however, we’ll do it backwards. First, I’ll provide you with the SQL statement and let’s see if you can explain it in plain English:

FROM Prices
WHERE StockNumber = 3006

So, what do you think this statement does? That’s right, it retrieves the price from the database for item 3006.

There’s one simple lesson you should take away from our discussion at this point: SQL is like English. Don’t worry about how you construct SQL statements; we’ll get to that in the rest of our series. Just realize that SQL isn’t as intimidating as it may first appear.

The Range of SQL Statements

SQL provides a wide range of statements, of which SELECT is just one. Here are some examples of other common SQL statements:

  • SQL INSERT and SQL DELETE: Inserts or deletes a record from a table
  • SQL UPDATE: Modifies records in a table
  • SQL CREATE and SQL DROP: Creates or deletes a table

In addition to these SQL statements, you can use SQL clauses, among them the WHERE clause used in the previous examples. These clauses serve to refine the type of data to act on. In addition to the WHERE clause, here are other commonly-used clauses:

  • AND or OR: Combine multiple conditions to refine a SQL statement
  • LIKE: Compares a value to similar values using a wildcard
  • ORDER BY: Sorts data in ascending or descending order

If you are interested in further exploring SQL, SQL Fundamentals is a multi-part tutorial that explores the components and aspects of SQL in more detail.