Rechercher dans le manuel MySQL
9.2.1 Identifier Qualifiers
Object names may be unqualified or qualified. An unqualified name is permitted in contexts where interpretation of the name is unambiguous. A qualified name includes at least one qualifier to clarify the interpretive context by overriding a default context or providing missing context.
For example, this statement creates a table using the
unqualified name t1
:
Because t1
includes no qualifier to specify a
database, the statement creates the table in the default
database. If there is no default database, an error occurs.
This statement creates a table using the qualified name
db1.t1
:
Because db1.t1
includes a database qualifier
db1
, the statement creates
t1
in the database named
db1
, regardless of the default database. The
qualifier must be specified if there is no
default database. The qualifier may be
specified if there is a default database, to specify a database
different from the default, or to make the database explicit if
the default is the same as the one specified.
Qualifiers have these characteristics:
An unqualified name consists of a single identifier. A qualified name consists of multiple identifiers.
The components of a multiple-part name must be separated by period (
.
) characters. The initial parts of a multiple-part name act as qualifiers that affect the context within which to interpret the final identifier.The qualifier character is a separate token and need not be contiguous with the associated identifiers. For example,
tbl_name.col_name
andtbl_name . col_name
are equivalent.If any components of a multiple-part name require quoting, quote them individually rather than quoting the name as a whole. For example, write
`my-table`.`my-column`
, not`my-table.my-column`
.A reserved word that follows a period in a qualified name must be an identifier, so in that context it need not be quoted.
The permitted qualifiers for object names depend on the object type:
A database name is fully qualified and takes no qualifier:
A table, view, or stored program name may be given a database-name qualifier. Examples of unqualified and qualified names in
CREATE
statements:A trigger is associated with a table, so any qualifier applies to the table name:
A column name may be given multiple qualifiers to indicate context in statements that reference it, as shown in the following table.
Column Reference Meaning col_name
Column col_name
from whichever table used in the statement contains a column of that nametbl_name.col_name
Column col_name
from tabletbl_name
of the default databasedb_name.tbl_name.col_name
Column col_name
from tabletbl_name
of the databasedb_name
In other words, a column name may be given a table-name qualifier, which itself may be given a database-name qualifier. Examples of unqualified and qualified column references in
SELECT
statements:
You need not specify a qualifier for an object reference in a
statement unless the unqualified reference is ambiguous. Suppose
that column c1
occurs only in table
t1
, c2
only in
t2
, and c
in both
t1
and t2
. Any unqualified
reference to c
is ambiguous in a statement
that refers to both tables and must be qualified as
t1.c
or t2.c
to indicate
which table you mean:
Similarly, to retrieve from a table t
in
database db1
and from a table
t
in database db2
in the
same statement, you must qualify the table references: For
references to columns in those tables, qualifiers are required
only for column names that appear in both tables. Suppose that
column c1
occurs only in table
db1.t
, c2
only in
db2.t
, and c
in both
db1.t
and db2.t
. In this
case, c
is ambiguous and must be qualified
but c1
and c2
need not be:
Table aliases enable qualified column references to be written more simply:
Traduction non disponible
Le manuel MySQL n'est pas encore traduit en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Document créé le 26/06/2006, dernière modification le 26/10/2018
Source du document imprimé : https://www.gaudry.be/mysql-rf-identifier-qualifiers.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.