Skip to content

Commit

Permalink
Docs: SCHEMAFULL table should be TYPE NORMAL by default (#781)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekwuno authored Aug 28, 2024
1 parent 1878f8b commit 03e7b01
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ SHOW CHANGES FOR TABLE reading SINCE u"2023-09-07T01:23:52Z" LIMIT 10;

The following example demonstrates the `SCHEMAFULL` portion of the `DEFINE TABLE` statement. When a table is defined as schemafull, the database strictly enforces any schema definitions that are specified using the `DEFINE TABLE` statement. New fields can not be added to a `SCHEMAFULL` table unless they are defined via the [`DEFINE FIELD`](/docs/surrealdb/surrealql/statements/define/field) statement.

:::note
__Note:__ Since `v2.0.0`, schemafull tables are implicitly type [`NORMAL`](/docs/surrealdb/surrealql/statements/define/table#table-with-specialized-type-clause) tables by default.
:::

```surql
-- Create schemafull user table.
DEFINE TABLE user SCHEMAFULL;
Expand Down Expand Up @@ -342,21 +346,28 @@ DEFINE TABLE OVERWRITE example;

<Since v="v1.4.0" />

With `TYPE ANY`, both relations and "normal" data can be stored on a table. Due to SurrealDB's schemaless nature, this is the default option if no `TYPE`-clause is specified.
When defining a table in SurrealDB, you can specify the type of data that can be stored in the table. This can be done using the `TYPE` clause, followed by either `ANY`, `NORMAL`, or `RELATION`.

With `TYPE ANY`, you can specify a table to store any type of data, whether it's a normal record or a relational record.

With `TYPE NORMAL`, you can specify a table to only store "normal" records, and not relations. When a table is defined as `TYPE NORMAL`, it will not be able to store relations this can be useful when you want to restrict the type of data that can be stored in a table in schemafull mode.

Finally, with `TYPE RELATION`, you can specify a table to only store relational type content. This can be useful when you want to restrict the type of data that can be stored in a table.

```surql
DEFINE TABLE person TYPE ANY;
-- Since it's default, we can also omit it.
DEFINE TABLE person;
```

With `TYPE NORMAL`, you can specify a table to only store "normal" records, and not relations.
With `TYPE NORMAL`, you can specify a table to only store "normal" records, and not relations.

```surql
-- Since it's default, we can also omit the TYPE clause
DEFINE TABLE person TYPE NORMAL;
```

With `TYPE RELATION`, you can specify a table to only store relation type content, and restrict what kind of relations can be stored.
With `TYPE RELATION`, you can specify a table to only store relational type content, and restrict what kind of relations can be stored.

```surql
-- Just a RELATION table, no constraints on the type of table
Expand All @@ -367,7 +378,7 @@ DEFINE TABLE likes TYPE RELATION FROM user TO post;
```

```surql
--
-- Define a relation table, and constraint the type of relation which can be stored
DEFINE TABLE assigned_to SCHEMAFULL TYPE RELATION IN tag OUT sticky
PERMISSIONS
FOR create, select, update, delete
Expand Down

0 comments on commit 03e7b01

Please sign in to comment.