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
BALANCEin the tableACCOUNTin the databaseBANKwould 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
BANKdatabase, you can reference theBANK.ACCOUNT.BALANCEcolumn simply asACCOUNT.BALANCE. In an SQL query where you have specified that you are selecting from theACCOUNTtable, 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 aSELECTstatement pulling from two tables that both haveBALANCEcolumns.- 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access