Skip to main content
Version: 2.x(alpha)

DEFINE DATABASE statement

The DEFINE DATABASE statement allows you to instantiate a named database, enabling you to specify security and configuration options.

Requirements

  • You must be authenticated as a root or namespace user before you can use the DEFINE DATABASE statement.
  • You must select your namespace before you can use the DEFINE DATABASE statement.

Statement syntax

SurrealQL Syntax
DEFINE DATABASE [ IF NOT EXISTS ] @name [ COMMENT @string ]

Example usage

Below shows how you can create a database using the DEFINE DATABASE statement.

-- Specify the namespace for the database
USE NS abcum;
-- Define database
DEFINE DATABASE app_vitalsense;

Using IF NOT EXISTS clause Since 1.3.0

The IF NOT EXISTS clause can be used to define a database only if it does not already exist. If the database already exists, the DEFINE DATABASE statement will return an error.

-- Create a DATABASE if it does not already exist
DEFINE DATABASE IF NOT EXISTS app_vitalsense;