Syntax

r.tableCreate(tableName, {optargs}) → result
r.db(dbName).tableCreate(tableName, {optargs}) → result

Arguments

List of arguments to provide.
tableName
string
required
Name of the table to create. Must be a valid table name following RuloDB naming conventions.

Optargs

No optional arguments.

Returns

result
object
Information about the operation.

Behavior

  • When called without a database context (r.tableCreate()), operates on the default database.
  • When called with a database context (r.db().tableCreate()), operates on the specified database.
  • The table is immediately available for use after creation.
  • If a table with the same name already exists, an error is thrown.
  • Automatically creates a primary key index on the id field.

Notes & Caveats

  • Table names must be less than 255 characters.
  • Table names must consist of ASCII alphanumeric characters, hyphens, and underscores.
  • Table names must be unique within the database.
  • The primary key field cannot be changed after table creation.

Example

Create a simple table

Create a basic users table in the default database.
const result = await r.tableCreate('users').run(client);

console.log(`Created ${result.created} table(s)`);

Create a table in a specific database

Create a table in the ecommerce database.
const result = await r.db('ecommerce').tableCreate('orders').run(client);

console.log(`Created ${result.created} table(s)`);
  • r - Referencing the query builder
  • db - Referencing a database
  • table - Referencing a table
  • tableDrop - Dropping a table
  • tableList - Listing tables

Found a typo? Or maybe a broken link? RuloDB is open-source, help us fix it!