Identifiers
Identifiers are names you make up to reference database objects. In MySQL, database objects consist of databases, tables, and columns. These objects fit into a hierarchical namespace whose root element is the database in question. You can reference any given object on a MySQL server—assuming you have the proper rights—using one of the following conventions:
- Absolute naming
Absolute naming is specifying the full tree of the object you are referencing. For example, the column
BALANCE
in the tableACCOUNT
in the databaseBANK
would be referenced absolutely as:BANK.ACCOUNT.BALANCE
- Relative naming
Relative naming allows you to specify only part of the object’s name, with the rest of the name being assumed based on your current context. For example, if you are currently connected to the
BANK
database, you can reference theBANK.ACCOUNT.BALANCE
column simply asACCOUNT.BALANCE
. In an SQL query where you have specified that you are selecting from theACCOUNT
table, you can reference the column using onlyBALANCE
. You must provide an extra layer of context whenever relative naming might result in ambiguity. An example of such ambiguity would be aSELECT
statement pulling from two tables that both haveBALANCE
columns.- Aliasing
Aliasing enables you to reference an object using an alternate name that helps avoid both ambiguity and the need to fully qualify a long name.
In general, MySQL allows you to use any character in an identifier.[1] This rule is limited, however, for databases ...
Get Managing & Using MySQL, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.