标识限定符

SQL语句中使用限定符来引用数据结构,例如数据库、表、字段。例如,一个SELECT查询中会包含一些字段以及至少一个表。

限定符可以由一个或多个identifiers组成,从其首字符开始到其结束字符中间的所有内容都会被解析:

  • 对于数据库而言,只需为数据库名称部分指定标识符。
  • 对于数据库中的对象(如,表、视图、函数等),可以为数据库名称部分指定标识符。如果没有指定数据库名称,将假定使用当前数据库(详细信息见USEDATABASE())。如果没有默认的数据库且没有指定数据库,将会报错。
  • 对于字段名称,一般可以从语句上下文中显而易见地知道表和数据库名称。但也可以指定表标识符,或者再加上数据库标识符。

如果限定符由一个以上的标识符组成,限定符之间必须使用点(.)进行分隔。所有标识符都可以单独被引号引起来。限定符之间允许有额外的空格(或新行、制表符)。

以下几个示例都是正确有效的:

  • db_name.tbl_name.col_name
  • tbl_name
  • `db_name`.`tbl_name`.`col_name`
  • `db_name` . `tbl_name`
  • db_name. tbl_name

如果表标识符有一个前缀点(.),将表示使用默认数据库。该语法是为了遵从ODBC,但在MariaDB中没有实际的作用。下面这些限定符是等价的:

  • tbl_name
  • . tbl_name
  • .`tbl_name`
  • . `tbl_name`
MariaDB starting with 10.0

MariaDB 10.0开始,DML语句可以使用PARTITION子句指定分区列表。详细信息见Partition Pruning and Selection

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.