REMOVE
statementThe REMOVE
statement is used to remove resources such as databases, tables, indexes, events and more. Similar to an SQL DROP statement.
SurrealQL SyntaxREMOVE [ NAMESPACE [ IF EXISTS ] @name | DATABASE [ IF EXISTS] @name | USER [ IF EXISTS ] @name ON [ ROOT | NAMESPACE | DATABASE ] | ACCESS [ 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 | TABLE [ IF EXISTS ] @name ]
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 ACCESS token ON NAMESPACE; REMOVE ACCESS user ON DATABASE; 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 TABLE article;
Available since: v1.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 ACCESS IF EXISTS token ON NAMESPACE; REMOVE ACCESS IF EXISTS user ON DATABASE; 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 TABLE IF EXISTS article;