SurrealDB Docs Logo

Enter a search query

Defining A Schema In Surrealist

Surrealist allows you to design your schemas both visually in the designer view and with queries in the query view, making it easy to create and manage your tables and relationships.

In this guide, you will walk through defining a schema in Surrealist.

What is a schema?

A schema is a blueprint of your database that defines the structure of your tables, the relationships between them, and the constraints that apply to your data.

Creating a new schema in the designer view

In Surrealist, you can create a new schema in the designer view by defining your tables and their columns, setting permissions, indexing, and establishing relationships between your tables.

To create a new schema in Surrealist, follow these steps:

  1. Open the designer view by clicking the designer icon in the sidebar.

  2. Click the + button to create a new table or a new relation between tables.

  3. Enter the table name and click the create button.

After your table is created, you can add columns by double-tapping the table name. You can then define permissions, changefeeds, fields, and constraints for the table. You can also toggle the table type depending on your requirements.

Note

By default, the table is schemaless, but you can enforce a schema by toggling the schema button.

Creating a new schema with the query view

You can also create a new schema in Surrealist using the query view by sending a DEFINE TABLE query.

For example, to define a new SCHEMAFULL table called users with columns firstname, lastname, and email, you can send the following query:

-- Create schemafull user table.
DEFINE TABLE user SCHEMAFULL;

-- Define some fields.
DEFINE FIELD firstName ON TABLE user TYPE string;
DEFINE FIELD lastName ON TABLE user TYPE string;
DEFINE FIELD email ON TABLE user TYPE string
  ASSERT string::is::email($value);
DEFINE INDEX userEmailIndex ON TABLE user COLUMNS email UNIQUE;

After defining the table, you can add data to the table, query the data, and perform other operations on the table.

© SurrealDB GitHub Discord Community Cloud Features Releases Install