SQL reference (MySQL and MariaDB dialects)

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#

SQL
name
`name`
`na``me`
database.table
table.column
database.table.column

Rules#

RuleRaft DB
Quotethe backtick. A backtick inside a quoted name is doubled. A double quote is never a name quote (see Literals).
Unquoted namesa 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 namesany characters, except what is excluded below. A quoted name may contain spaces and accents.
Lengthat 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 dotMySQL takes any word after a dot as a name (p.order, t.group); so does Raft DB.
Reserved wordsa reserved word must be quoted to be used as a name (see Reserved words).

Remarks#

  • Case. Column names are compared without regard to case (Name and name are the same column). Database and table names are looked up as they are written, as on a MySQL server with lower_case_table_names = 0: Words and words are two names. (Real MySQL on Windows has lower_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 by SHOW TABLES and SHOW 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_mysql and __rdb_mariadb mark a database as made by that front-end: each front-end lists only the databases it made.
  • Aliases. An alias may be written with AS or without it; a reserved word cannot be an alias unless it is quoted.
  • Qualified names. db.table names a table of another database than the default one. A column is written table.column or db.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#

SQL
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)