6.1. Identifier Syntax


Identifiers may be unquoted or quoted. If unquoted, an identifier must follow these rules:

  • An identifier may contain all alphanumeric characters, the underline character ('_'), and the dollar sign ('$').

  • An identifier may begin with any of the legal characters, even a digit. However, it's best to avoid identifiers that might be misinterpreted as constants. For example, 1e3 might be taken as a number in scientific notation, and 0x1 might be interpreted as a hex constant. Therefore, neither is a good choice for an identifier.

  • An identifier cannot consist entirely of digits.

An identifier may be quoted, in which case it can contain characters such as spaces or dashes that aren't otherwise legal. To quote an identifier, you may enclose it within backtick ('`') characters. If the ANSI_QUOTES SQL mode is enabled, you may also quote an identifier by enclosing it within double quotes ('"'). Quoting causes the identifier syntax rules to be relaxed as follows:

  • In general, any character may be used in a quoted identifier. Exceptions are that an identifier cannot contain a byte with a numeric value of 0 or 255, and database and table names cannot contain '.', '/', or '\'.

  • A quoted identifier may consist entirely of digits.

An alias identifier can include any character, but should be quoted if it's a reserved word (such as SELECT or DESC), contains special characters, or consists entirely of digits. Aliases may be quoted within single quotes ('''), double quotes, or backticks. Within a quoted identifier, to include the quote character, double it.

If you aren't sure whether an identifier is legal, quote it. It's harmless to put quotes around an identifier that's legal without them.



MySQL 5 Certification Study Guide
MySQL 5.0 Certification Study Guide
ISBN: 0672328127
EAN: 2147483647
Year: 2006
Pages: 312

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net