Skip to content
Course content preview

15: Viewing the schema

Another advantage to having a schema is that the Designer view inside SurrealDB Studio can use it to show a graphical overview of the types used in the database.

Without a schema, it isn't able to show much of anything. At the moment, all that it knows is that the database has two tables. But it has no idea whether name will always be a string, or whether libraries will always be an array that holds place records.

A database schema containing two table names, place and town, and nothing else

The whole table doesn't need to be made SCHEMAFULL though. Instead, DEFINE FIELD can be used to define just one field at a time. This lets the table stay flexible for the most part, except for certain fields that we want to behave in a certain way.

Here is the DEFINE FIELD statement we used for practice on the last page.

DEFINE FIELD population ON schemafull_town TYPE number;


Following this format, we can define five fields to ensure that the fields for the place and town records can only be of a certain type.

-- Statements for the 'place' table
DEFINE FIELD address ON place TYPE string;
DEFINE FIELD name ON place TYPE string;

-- Statements for the 'town' table
DEFINE FIELD name ON town TYPE string;
DEFINE FIELD population ON town TYPE int;
DEFINE FIELD libraries ON town TYPE option<array<record<place>>>;

INFO FOR TABLE place;
INFO FOR TABLE town;


The INFO FOR TABLE statements are no longer empty, showing the definitions for each field.

Output · Query 1
{
  events: {},
  fields: {
    address: 'DEFINE FIELD address ON place TYPE string PERMISSIONS FULL',
    name: 'DEFINE FIELD name ON place TYPE string PERMISSIONS FULL'
  },
  indexes: {},
  lives: {},
  tables: {}
}
Output · Query 2
{
  events: {},
  fields: {
    libraries: 'DEFINE FIELD libraries ON town TYPE option<array<record<place>>> PERMISSIONS FULL',
    "libraries.*": 'DEFINE FIELD libraries.* ON town TYPE record<place> PERMISSIONS FULL',
    name: 'DEFINE FIELD name ON town TYPE string PERMISSIONS FULL',
    population: 'DEFINE FIELD population ON town TYPE int PERMISSIONS FULL'
  },
  indexes: {},
  lives: {},
  tables: {}
}


The type of the last DEFINE FIELD statement above is a bit long: option<array<record<place>>>. That is because:

  • Records are always of type record<record_name>, so places are record<place> and towns are record<town>.

  • The libraries field should be able to hold more than one record, which gives us array<record<place>>.

  • Not all towns have libraries, so we don't want to return an error if a town doesn't have this field. By wrapping it in an option, the libraries field doesn't need to be set in order to create a town.

Once these statements are executed, SurrealDB Studio will be able to make a much more informative graphical schema for us.

A database schema containing the same town and place tables, but with their fields now indicated along with a record link between the two

THE PLATFORM

Everything an application and its agents know. Five surfaces, one engine.

IN PRODUCTION

Trusted at scale. Samsung, Nvidia, Verizon, Tencent and Walmart run on SurrealDB.

14,000+

Developers building on SurrealDB Cloud

4M+

Developers building on SurrealDB worldwide

FROM THE TEAMS

SurrealDB gives us a foundation where we can unify semantic search, knowledge graphs, and AI-driven decision making without stitching together multiple systems. Collapsing responsibility into SurrealDB has become our default engineering posture.
Justin Foley

VP of Engineering, Later

SurrealDB

The context and memory layer for AI agents

Database. Graphs, vectors, documents and relational data in one engine, in a single ACID transaction.
Agent Memory. Connects and retrieves context wherever your data lives, every fact carrying its source.
Cloud. Fully managed, in the cloud provider and region you choose.

Explore with AI

Copyright © 2026 SurrealDB Ltd. Registered in England and Wales. Company no. 13615201

Registered address: 3rd Floor 1 Ashley Road, Altrincham, Cheshire, WA14 2DT, United Kingdom

Trading address: Huckletree Oxford Circus, 213 Oxford Street, London, W1D 2LG, United Kingdom