GNU Info

Info Node: (mysql.info)Legal names

(mysql.info)Legal names


Next: Name case sensitivity Prev: Literals Up: Language Structure
Enter node , (file) or (file)node

Database, Table, Index, Column, and Alias Names
-----------------------------------------------

Name case sensitivity
Case sensitivity in names
Database, table, index, column, and alias names all follow the same
rules in MySQL.

Note that the rules changed starting with MySQL Version 3.23.6 when we
introduced quoting of identifiers (database, table, and column names)
with ``'. `"' will also work to quote identifiers if you run in ANSI
mode. Note: ANSI mode.

*Identifier**Max        *Allowed characters*
            length*     
Database    64          Any character that is allowed in a directory name
                        except `/' or `.'.
Table       64          Any character that is allowed in a file name,
                        except `/' or `.'.
Column      64          All characters.
Alias       255         All characters.

Note that in addition to the above, you can't have ASCII(0) or
ASCII(255) or the quoting character in an identifier.

Note that if the identifier is a restricted word or contains special
characters you must always quote it with ``' when you use it:

     SELECT * from `select` where `select`.id > 100;

In previous versions of MySQL, the name rules are as follows:

   * A name may consist of alphanumeric characters from the current
     character set and also `_' and `$'. The default character set is
     ISO-8859-1 Latin1; this may be changed with the
     `--default-character-set' option to `mysqld'.  Note: Character
     sets.

   * A name may start with any character that is legal in a name.  In
     particular, a name may start with a number (this differs from many
     other database systems!).  However, a name cannot consist _only_
     of numbers.

   * You cannot use the `.' character in names because it is used to
     extend the format by which you can refer to columns (see
     immediately below).

It is recommended that you do not use names like `1e', because an
expression like `1e+1' is ambiguous. It may be interpreted as the
expression `1e + 1' or as the number `1e+1'.

In MySQL you can refer to a column using any of the following forms:

*Column reference*        *Meaning*
`col_name'                Column `col_name' from whichever table used in
                          the query contains a column of that name.
`tbl_name.col_name'       Column `col_name' from table `tbl_name' of the
                          current database.
`db_name.tbl_name.col_name'Column `col_name' from table `tbl_name' of the
                          database `db_name'.  This form is available in
                          MySQL Version 3.22 or later.
``column_name`'           A column that is a keyword or contains special
                          characters.

You need not specify a `tbl_name' or `db_name.tbl_name' prefix for a
column reference in a statement unless the reference would be ambiguous.
For example, suppose tables `t1' and `t2' each contain a column `c',
and you retrieve `c' in a `SELECT' statement that uses both `t1' and
`t2'.  In this case, `c' is ambiguous because it is not unique among
the tables used in the statement, so you must indicate which table you
mean by writing `t1.c' or `t2.c'.  Similarly, if you are retrieving
from a table `t' in database `db1' and from a table `t' in database
`db2', you must refer to columns in those tables as `db1.t.col_name'
and `db2.t.col_name'.

The syntax `.tbl_name' means the table `tbl_name' in the current
database.  This syntax is accepted for ODBC compatibility, because some
ODBC programs prefix table names with a `.' character.


automatically generated by info2www version 1.2.2.9