TypeDB 3.0 is live! Get started for free.

Undefine query

Undefine queries are used to remove existing types, constraints, or functions from the schema.

Syntax

Undefine queries start with the undefine keyword following by undefinition statements.

undefine
  <undefinition_statements>

Undefinition statements are similar to definition statements, but they have a different structure to highlight which part of the definition is to be undefined, in some cases using the from keyword.

Type undefinition statement
<label>;
Trait undefinition statement
<trait_definition> from <type_label>;
Annotation undefinition statement
<@annotation> from <type_label_or_trait>;
Function undefinition statement
fun <function name>;

Statements should be separated by semicolons. Schema statements in an undefine query cannot use variables or values.

Behavior

An undefine query removes the parts of the schema specified in its undefine clause, including types, traits, annotations, and functions. Undefining a type also undefines all its traits and annotations. Undefining a trait also undefines all its traits and annotations.

An error is returned (on execution or on commit), and no changes are preserved, if:

  • There is no existing definition to undefine.

  • The query results in an invalid schema.

Statements

Examples

Undefining types

Undefining a type
undefine user;
Undefining types
undefine parentship; email;

Undefining traits

Undefining relation type’s relates
undefine relates child from parentship;
Undefining relation type’s subtyping
undefine sub parentship from fathership;
Undefining relates specialization
undefine as parent from fathership relates father;
Undefining type’s roleplaying
undefine plays parentship:parent from user;
Undefining attribute type’s value type
undefine value string from email;
Undefining type’s ownership
undefine owns email from user;

Undefining annotations

Undefining type’s annotation without arguments
undefine @abstract from parentship;
Undefining value type’s annotation with arguments
undefine @regex from email value string;
Undefining type’s and type’s ownership’s annotations
undefine
  @card from user owns email;
  @independent from email;

Undefining functions

To undefine a function, specify the fun keyword and its name.

undefine
  fun karma_with_squared_value;