8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 85%

22.3.4 关系表22.3.4 Relational Tables

您也可以使用 X DevAPI 来操作关系表。在 MySQL 中,每个关系表都关联特定的存储引擎。本节中的示例使用 InnoDB 表,这些表位于 world_x 模式中。You can also use X DevAPI to work with relational tables. In MySQL, each relational table is associated with a particular storage engine. The examples in this section use InnoDB tables in the world_x schema.

确认模式Confirm the Schema

要显示分配给 db 全局变量的模式,请执行 db。To show the schema that is assigned to the db global variable, issue db.

mysql-js> db
<Schema:world_x>

如果返回的值不是 Schema:world_x,请按如下方式设置 db 变量:If the returned value is not Schema:world_x, set the db variable as follows:

mysql-js> \use world_x
Schema `world_x` accessible through db.

显示所有表Show All Tables

要显示 world_x 架构中的所有关系表,请在 db 对象上使用 getTables() 方法。To display all relational tables in the world_x schema, use the getTables() method on the db object.

mysql-js> db.getTables()
{
    "city": <Table:city>,
    "country": <Table:country>,
    "countrylanguage": <Table:countrylanguage>
}

基本表操作Basic Table Operations

按表范围的基本操作包括:Basic operations scoped by tables include:

操作形式Operation form 说明Description
db.name.insert() insert() 方法将一个或多个记录插入指定表中。The insert() method inserts one or more records into the named table.
db.name.select() select() 方法返回指定表中的部分或全部记录。The select() method returns some or all records in the named table.
db.name.update() update() 方法更新指定表中的记录。The update() method updates records in the named table.
db.name.delete() delete() 方法从指定表中删除一个或多个记录。The delete() method deletes one or more records from the named table.

相关信息Related Information