Database Reference
In-Depth Information
Transaction control language (TCL) statements, which are used to mark transac-
tion boundaries and control transaction behavior.
Data control language (DCL) statements, which are used to grant database permis-
sions (or to revoke those permissions) to users and groups, so that the users or groups
can perform various operations on the data in the database
This chapter considers only DML statements for querying data. The remaining DML statements
for inserting, modifying, and deleting data are discussed in Chapter 7, where we will also discuss
SQL DDL statements. SQL/PSM is introduced in Chapter 7, and the specific variations of it used
with each DBMS are discussed in detail in Chapter 10A for Microsoft SQL Server 2012, Chapter 10B
for Oracle Database 11 g Release 2, and Chapter 10C for MySQL 5.6. TCL and DCL statements are
discussed in Chapter 9.
By The Way Some authors treat SQL queries as a separate part of SQL rather than as
a part of SQL DML. We note that the SQL/Framework section of the SQL
specification includes queries as part of the “SQL-data statements” class of statements
along with the rest of the SQL DML statements and treat them as SQL DML statements.
By The Way The four actions listed for SQL DML are sometimes referred to as CRUD:
create, read, update, and delete. We do not use this term in this topic, but
now you know what it means.
SQL is ubiquitous, and SQL programming is a critical skill. Today, nearly all DBMS products
process SQL, with the only exceptions being some of the emerging NoSQL and Big Data move-
ment products. Enterprise-class DBMSs such as Microsoft SQL Server 2012, Oracle Database 11 g
Release 2, Oracle MySQL 5.6, and IBM DB2 require that you know SQL. With these products, all
data manipulation is expressed using SQL.
As explained in Chapter 1, if you have used Microsoft Access, you have used SQL, even if
you didn't know it. Every time you process a form, create a report, or run a query, Microsoft
Access generates SQL and sends that SQL to Microsoft Access's internal ADE DBMS engine.
To do more than elementary database processing, you need to uncover the SQL hidden by
Microsoft Access. Further, once you know SQL, you will find it easier to write a query state-
ment in SQL rather than fight with the graphical forms, buttons, and other paraphernalia that
you must use to create queries with the Microsoft Access query-by-example style GUI.
The SQL SeLeCT/FROM/WheRe Framework
This section introduces the fundamental statement framework for SQL query statements. After
we discuss this basic structure, you will learn how to submit SQL statements to Microsoft Access,
Microsoft SQL Server, Oracle Database, and MySQL. If you choose, you can then follow along with
the text and process the SQL statements as they are explained in the rest of this chapter. The basic
form of SQL queries uses the SQL SELECT/FROM/WHERE framework . In this framework:
The SQL SELECT clause specifies which columns are to be listed in the query results.
The SQL FROM clause specifies which tables are to be used in the query.
The SQL WHERE clause specifies which rows are to be listed in the query results.
Let's work through some examples so that this framework makes sense to you.
Reading Specified Columns from a Single Table
We begin very simply. Suppose we want to obtain just the values of the Department and Buyer
columns of the SKU_DATA table. An SQL statement to read that data is the following:
SELECT
Department, Buyer
FROM
SKU_DATA;
 
 
Search WWH ::




Custom Search