6.3. Using Qualified Names


Column and table identifiers can be written in qualified form that is, together with the identifier of a higher-level element, with a period ('.') separator. Sometimes qualifiers are necessary to resolve ambiguity. Other times you may elect to use them simply to make a statement clearer or more precise.

A table name may be qualified with the name of the database to which it belongs. For example, the Country table in the world database may be referred to as world.Country, where a '.' character is placed between the two identifiers in the name. If world is the default database, these statements are equivalent:

 SELECT * FROM Country; SELECT * FROM world.Country; 

A column name may be qualified with the name of the table to which it belongs. For example, the Name column in the Country table may be referred to as Country.Name.

A further level of column qualification is possible because a table name may be qualified with a database name. So, another way to refer to the Name column is world.Country.Name. If world is the default database, the following statements are equivalent. They differ only in having successively more specific levels of name qualification:

 SELECT Name FROM Country; SELECT Country.Name FROM Country; SELECT world.Country.Name FROM world.Country; 

Stored routines and triggers also may be referred to in qualified form. Qualify a stored routine with the name of the database that it belongs to (db_name.routine_name). A trigger is associated with a table, so a trigger identifier should be qualified with a table identifier (table_name.trigger_name).

To use quoted identifiers in a qualified name, quote them separately. For example, quote world.Country as `world`.`Country`, not as `world.Country`.



MySQL 5 Certification Study Guide
MySQL 5.0 Certification Study Guide
ISBN: 0672328127
EAN: 2147483647
Year: 2006
Pages: 312

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net