SQL 2008 Essentials

Page 78

2.7

SYNONYMS

63

Once again, multitable queries will be discussed from Chapter 4 onward. Following is an example of a query with a table qualifier used for the age column: SELECT * FROM Dependent WHERE Dependent.age > 5 This produces the following output: PNO -----2 62 128 144 145 146 147 158

DNAME -------------------Beena Tom Barbara Susan Susie Xi du Barbara Sally

RELATIONSHIP -----------Spouse Husband Wife Wife Wife Wife Wife Wife

SEX ---F M F F F F F F

AGE -----19 25 18 19 21 20 20 20

(8 row(s) affected) It is very common in SQL to alias a table and then use the table alias as a table qualifier, as illustrated here: SELECT * FROM Dependent d WHERE d.age > 5 The output of this query is the same as the output of the previous query. In this query, d (the table alias) is also the table qualifier. Not only is a construction like this very common, but it also helps to prevent typing errors when writing commands. The advantages of using table qualifiers and table aliases may not be so apparent in the examples presented in this chapter since we are only working with single tables here. As we start working with multiple tables (from Chapter 4 onward), their advantages will become more obvious.

2.7 Synonyms In the last section, we discussed one way of referring to a table—through the use of table aliases. Table aliases are not permanent in the sense that


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.