SQL: The language of Db2

The language that you use to access the data in Db2 tables is the structured query language (SQL). SQL is a standardized language for defining and manipulating data in a relational database.

The language consists of SQL statements. You can issue SQL statements to accomplish the following actions:

  • Define, modify, or drop data objects, such as tables.
  • Retrieve, insert, update, or delete data in tables.

You can use other SQL statements to authorize users to access specific resources, such as tables or views.

When you write an SQL statement, you specify what you want done, not how to do it. To access data, for example, you need only to name the tables and columns that contain the data. You do not need to describe how to get to the data.

In accordance with the relational model of data:

  • The database is perceived as a set of tables.
  • Relationships are represented by values in tables.
  • Data is retrieved by using SQL to specify a result table that can be derived from one or more tables.

Db2 transforms each SQL statement, that is, the specification of a result table, into a sequence of operations that optimize data retrieval. This transformation occurs when the SQL statement is prepared. This transformation is also known as binding.

All executable SQL statements must be prepared before they can run. The result of preparation is the executable or operational form of the statement.

As the following example illustrates, SQL is generally intuitive.

Begin general-use programming interface information.

Example

Assume that you are shopping for shoes and you want to know what shoe styles are available in size 8. The SQL query that you need to write is similar to the question that you would ask a salesperson, "What shoe styles are available in size 8?" Just as the salesperson checks the shoe inventory and returns with an answer, Db2 retrieves information from a table (SHOES) and returns a result table. The query looks like this:
SELECT STYLE
  FROM SHOES
  WHERE SIZE = 8;

Assume that the answer to your question is that two shoe styles are available in a size 8: loafers and sandals. The result table looks like this:

STYLE 
=======
LOAFERS
SANDALS
End general-use programming interface information.

SQL standards

Db2 for z/OS® is developed based on industry SQL standards. For details, see Industry standards and Db2 for z/OS.

Syntax diagrams for SQL statements

For more information about the conventions for syntax diagrams in the Db2 product documentation, see How to read syntax diagrams.

Where to find PDF format and online content

The following table shows where to find the PDF format and online content from this section of the Db2 for z/OS product documentation.