|
Home
/ Technical Support / MySQL
Key Offerings:
B2B and B2C E-Business
Solutions
Offshore
Software Development Outsourcing
Strategic Consulting
Offshore Software Outsourcing
ALTOROS Systems
is headquartered in Tampa, Florida and maintains an office
near Boston, Massachusetts and technology development center
in Belarus and Russia. ALTOROS specializes on providing value-added
e-commerce and web-based software development and offshore
software outsourcing services to emerging enterprises helping
them successfully plan and implement business initiatives.
Contact Us for more
information.
Database, Table, Index, Column, and Alias 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. See ANSI mode.
| Identifier |
Max length |
Allowed characters |
| 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:
mysql> SELECT * FROM `select` WHERE `select`.id > 100;
In MySQL versions prior to 3.23.6, 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. See Character sets.
· A name may start with any character that is legal in a name. In particular, a name may start with a digit (this differs from many other database systems!). However, a name cannot consist only of digits.
· 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.
|