Identifiers
How to name databases, tables, columns and other objects: quoting, characters, the 64 character limit, case, and the names Raft DB keeps for itself.
An identifier is the name of a database, table, column, index, constraint, view, sequence, routine, trigger, window or alias.
Syntax#
name
`name`
`na``me`
database.table
table.column
database.table.columnRules#
| Rule | Raft DB |
|---|---|
| Quote | the backtick. A backtick inside a quoted name is doubled. A double quote is never a name quote (see Literals). |
| Unquoted names | a letter, a digit, _ or $, or any character above U+007F (accents and other scripts). A name may start with digits when it is not a number (8984444cce5e). |
| Quoted names | any characters, except what is excluded below. A quoted name may contain spaces and accents. |
| Length | at most 64 characters (not bytes). |
| Not allowed in a database or table name | ., /, \, any control character (below U+0020), a space at the end. |
| After a dot | MySQL takes any word after a dot as a name (p.order, t.group); so does Raft DB. |
| Reserved words | a reserved word must be quoted to be used as a name (see Reserved words). |
Remarks#
- Case. Column names are compared without regard to case (
Nameandnameare the same column). Database and table names are looked up as they are written, as on a MySQL server withlower_case_table_names = 0:Wordsandwordsare two names. (Real MySQL on Windows haslower_case_table_names = 1; making Raft DB follow that is an open item.) The spelling you used when you created the object is kept and shown bySHOW TABLESandSHOW CREATE TABLE. This is separate from the comparison of text values, which ignores case (see Collation and case sensitivity). - Any name MySQL allows. Raft DB itself takes only letters, digits,
_and-in the names of its own tables, so the front-end stores a name with other characters encoded (a prefix_u_and then each byte as itself or as_xx). You do not see this; it matters only to someone who lists Raft DB's tables directly (the engine's limit is 255 bytes of encoded name). - Names Raft DB reserves. The connector keeps its own tables in each database, named
__rdb_...(the table definitions, sequences, routines, triggers),__tmp...(temporary tables of sessions) and__u_.... A table or database whose name starts with one of these is refused. Other names that start with__are allowed. The tables__rdb_mysqland__rdb_mariadbmark a database as made by that front-end: each front-end lists only the databases it made. - Aliases. An alias may be written with
ASor without it; a reserved word cannot be an alias unless it is quoted. - Qualified names.
db.tablenames a table of another database than the default one. A column is writtentable.columnordb.table.column. - Column names in results. A select item without an alias is named by its text as written, as in MySQL.
- Names that are only digits are read as numbers, not names: quote them.
Examples#
CREATE TABLE `odd name` (a INT);
CREATE TABLE p (id INT PRIMARY KEY, `condition` VARCHAR(10), `order` INT, `from` INT, `to` INT);
SELECT p.condition, p.order, p.from, p.to FROM p WHERE p.from = 0 OR p.to >= 6;
CREATE TABLE __hidden (a INT); -- allowed: only __rdb_, __tmp and __u_ are reserved
```7.
## See also
* [Reserved words](/docs/sql-reference/reserved-words)
* [Literals](/docs/sql-reference/literals)
* [CREATE TABLE statement](/docs/sql-reference/create-table)
* [Collation and case sensitivity](/docs/sql-reference/collation-and-case)