Skip to main content

REMOVE statement

The REMOVE statement is used to remove resources such as databases, tables, indexes, events and more. Similar to an SQL DROP statement.

Statement syntax

SurrealQL Syntax
REMOVE [
NAMESPACE [ IF EXISTS ] @name
| DATABASE [ IF EXISTS] @name
| USER [ IF EXISTS ] @name ON [ ROOT | NAMESPACE | DATABASE ]
| TOKEN [ IF EXISTS ] @name ON [ NAMESPACE | DATABASE ]
| EVENT [ IF EXISTS ] @name ON [ TABLE ] @table
| FIELD [ IF EXISTS ] @name ON [ TABLE ] @table
| INDEX [ IF EXISTS ] @name ON [ TABLE ] @table
| ANALYZER [ IF EXISTS ] @name
| FUNCTION [ IF EXISTS ] fn::@name
| PARAM [ IF EXISTS ] $@name
| SCOPE [ IF EXISTS ] @name
| TABLE [ IF EXISTS ] @name
]

Example usage

Basic usage

The following queries show an example of how to remove resources

REMOVE NAMESPACE surrealdb;

REMOVE DATABASE blog;

REMOVE USER writer ON NAMESPACE;

REMOVE USER writer ON DATABASE;

REMOVE TOKEN writer_token ON NAMESPACE;

REMOVE EVENT new_post ON TABLE article;

-- Only works for Schemaful tables (i.e. tables with a schema)
REMOVE FIELD tags ON TABLE article;

REMOVE INDEX authors ON TABLE article;

REMOVE ANALYZER example_ascii;

REMOVE FUNCTION fn::update_author;

REMOVE PARAM $author;

REMOVE SCOPE documentation;

REMOVE TABLE article;

Using if exists clause Since 1.3.0

The following queries show an example of how to remove resources using the IF EXISTS clause, which will only remove the resource if it exists.

REMOVE NAMESPACE IF EXISTS surrealdb;

REMOVE DATABASE IF EXISTS blog;

REMOVE USER IF EXISTS writer ON NAMESPACE;

REMOVE USER IF EXISTS writer ON DATABASE;

REMOVE TOKEN IF EXISTS writer_token ON NAMESPACE;

REMOVE EVENT IF EXISTS new_post ON TABLE article;

-- Only works for Schemaful tables (i.e. tables with a schema)
REMOVE FIELD IF EXISTS tags ON TABLE article;

REMOVE INDEX IF EXISTS authors ON TABLE article;

REMOVE ANALYZER IF EXISTS example_ascii;

REMOVE FUNCTION IF EXISTS fn::update_author;

REMOVE PARAM IF EXISTS $author;

REMOVE SCOPE IF EXISTS documentation;

REMOVE TABLE IF EXISTS article;