Database Reference
In-Depth Information
Using the data in Figure 2-5, when the DBMS processes this statement the result will be:
When SQL statements are executed, the statements transform tables. SQL statements
start with a table, process that table in some way, and then place the results in another table
structure. Even if the result of the processing is just a single number, that number is considered
to be a table with one row and one column. As you will learn at the end of this chapter, some
SQL statements process multiple tables. Regardless of the number of input tables, though, the
result of every SQL statement is a single table.
Notice that SQL statements terminate with a semicolon (;) character. The semicolon is
required by the SQL standard. Although some DBMS products will allow you to omit the semi-
colon, some will not, so develop the habit of terminating SQL statements with a semicolon.
SQL statements can also include an SQL comment , which is a block of text that is used
to document the SQL statement while not executed as part of the SQL statement. SQL com-
ments are enclosed in the symbols /* and */ , and any text between these symbols is ignored
when the SQL statement is executed. For example, here is the previous SQL query with an SQL
comment added to document the query by including a query name:
/* *** SQL-Query-CH02-01 *** */
SELECT Department, Buyer
FROM SKU_DATA;
Because the SQL comment is ignored when the SQL statement is executed, the output from
this query is identical to the query output shown above. We will use similar comments to label the
SQL statements in this chapter as an easy way to reference a specific SQL statement in the text.
Specifying Column Order in SQL Queries from a Single Table
The order of the column names in the SELECT phrase determines the order of the columns in
the results table. Thus, if we switch Buyer and Department in the SELECT phrase, they will be
switched in the output table as well. Hence, the SQL statement:
/* *** SQL-Query-CH02-02 *** */
SELECT Buyer, Department
FROM SKU_DATA;
produces the following result table:
 
Search WWH ::




Custom Search