Skip to content

Informatics Practices · Ch 7 — Introduction to Structured Query Language (SQL)

Structured Query Language (SQL)

7.2

Structured Query Language (SQL)

The heart of this section is a contrast between two ways of reaching data. In an ordinary file system, there is no built-in way to ask for data — a programmer must write a full application program for every kind of access. A database management system removes that burden: it comes with a special kind of programming language, called a query language, designed purely for accessing data from the database.

The Structured Query Language (SQL) is the most popular query language in use, and it is the language spoken by all the major relational database management systems — MySQL, ORACLE, SQL Server, and others. Knowing SQL therefore means knowing how to talk to practically any serious RDBMS.

Two qualities make SQL easy to learn:

  • Its statements are built from descriptive English words, so a statement often reads almost like a plain sentence.
  • It is not case sensitive, so you need not worry about capitalisation while writing statements.

There is a deeper convenience as well, and it is SQL's defining benefit: we never have to specify how to get the data from the database. We simply state what is to be retrieved, and SQL works out the rest. This "say what, not how" style is what separates a query language from ordinary programming, where the programmer must spell out every step of the procedure.

Although its name calls it a query language, SQL can do much more than query. It provides statements for:

  • defining the structure of the data (what tables exist and what columns they contain),
  • manipulating data in the database (putting data in and changing it),
  • declaring constraints (rules the data must obey), and
  • retrieving data from the database in a variety of ways, depending on the requirement at hand. …