# Undefine query

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

## [](#_syntax)Syntax

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

```typeql
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

```typeql
<label>;
```

capability undefinition statement

```typeql
<interface_definition> from <type_label>;
```

Annotation undefinition statement

```typeql
<@annotation> from <type_label_or_interface>;
```

Function undefinition statement

```typeql
fun <function name>;
```

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

## [](#_behavior)Behavior

An undefine query removes the parts of the schema specified in its undefine clause, including types, capabilities, annotations, and functions. Undefining a type also undefines all its capabilities 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_behavior)Statements

*   [`relates …​ from` statements](../../statements/relates/index.md) undefine existing relates and role types.
    
*   [`as …​ from relates` statements](../../statements/relates/index.md) undefine existing relates specializations.
    
*   [`plays …​ from` statements](../../statements/plays/index.md) undefine existing roleplayings.
    
*   [`owns …​ from` statements](../../statements/owns/index.md) undefine existing ownerships.
    
*   [`value …​ from` statements](../../statements/value/index.md) undefine existing attribute types' value types.
    
*   [`sub …​ from` statements](../../statements/sub/index.md) undefine existing subtyping connections.
    
*   [`@annotation …​ from` statements](../../annotations/index.md) undefine existing annotations. Only the type of the annotation is required, so annotations with arguments can be undefined without their arguments specification.
    
*   [`fun …​` statements](../../statements/fun/index.md) undefine existing functions.
    

## [](#_examples)Examples

Schema for the following examples

```typeql
#!test[schema, commit]
define
  entity content owns id;
  entity page sub content,
    owns page-id,
    owns name;
  entity profile sub page,
    owns username;
  entity user sub profile,
    owns phone,
    owns karma;

  attribute id value string;
  attribute page-id sub id;
  attribute username sub page-id;
  attribute name value string;
  attribute phone value string;
  attribute karma value double;
attribute bio value string;
attribute profile-picture value string;
attribute email @independent, value string @regex("^.*@.*\.com");
user owns bio, owns profile-picture, owns email;
attribute tag value string;
entity post owns tag @card(0..);
relation parentship @abstract, relates parent, relates child;
relation fathership sub parentship, relates father as parent;
user plays parentship:parent;
user owns email @card(0..1);
```

### [](#_undefining_types)Undefining types

Undefining a type

```typeql
#!test[schema, rollback]
undefine user;
```

Undefining types

```typeql
#!test[schema, rollback]
undefine fathership; email;
```

### [](#_undefining_capabilities)Undefining capabilities

Undefining relation type’s relates

```typeql
#!test[schema]
undefine relates child from parentship;
```

Undefining relates specialization

```typeql
#!test[schema]
undefine as parent from fathership relates father;
```

Undefining relation type’s subtyping

```typeql
#!test[schema]
# Note, this requires the specialisation to have been undefined first.
undefine sub parentship from fathership;
```

Undefining type’s roleplaying

```typeql
#!test[schema]
undefine plays parentship:parent from user;
```

Undefining attribute type’s value type

```typeql
#!test[schema, fail_at=runtime]
undefine value string from email;
```

Undefining type’s ownership

```typeql
#!test[schema, rollback]
undefine owns email from user;
```

### [](#_undefining_annotations)Undefining annotations

Undefining type’s annotation without arguments

```typeql
#!test[schema]
undefine @abstract from parentship;
```

Undefining value type’s annotation with arguments

```typeql
#!test[schema]
undefine @regex from email value string;
```

Undefining type’s and type’s ownership’s annotations

```typeql
#!test[schema]
undefine
  @card from user owns email;
  @independent from email;
```

### [](#_undefining_functions)Undefining functions

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

```typeql
#!test[schema]
undefine
  fun karma_with_squared_value;
```

[Define](../define/index.md) [Redefine](../redefine/index.md)

[Edit on GitHub](https://github.com/typedb/typedb-docs/edit/3.x-development/typeql-reference/modules/ROOT/pages/schema/undefine.adoc) Edit this page on GitHub.