Undefine query
In this guide, you’ll see how to use an Undefine query to undefine types and rules in a database schema using Studio, Console, or one of the drivers.
Understanding Undefine queries
A Undefine query is used to delete type and rule definitions from a schema. For a detailed explanation of the query see the Undefine query page. For an alternative way of editing your schema, see the Schema editing page.
Sending Undefine queries
Before you begin, ensure you’ve followed the instructions from the Define query page. The easiest way to send an Undefine query is to use Studio or Console:
-
Studio
-
Console
Follow the Studio manual to connect to TypeDB and select a project folder. Then use the steps below:
-
Use a drop-down list in the top toolbar to select a database.
-
Switch to
schema
session andwrite
transaction types. -
Open a new tab and insert or type in a Undefine query, for example:
TypeQL Undefine queryundefine admin sub user;
-
Run the query by clicking the Run Query button.
-
Commit the changes by clicking the Commit query button.
Follow the Connect to server guide to connect to TypeDB. Then use the steps below:
-
Open a
schema
session andwrite
transaction to the selected database (e.g.,sample_db
):transaction sample_db schema write
-
Send the Undefine query:
undefine admin sub user;
Push Enter twice to send the query.
-
Commit the changes:
commit
To send a Undefine query programmatically, use drivers:
-
Rust
-
Python
-
Node.js
-
Java
-
C#
-
C++
-
C
Follow the connection guide
to connect the driver
to a TypeDB server, then open a schema
session to the selected database,
open a write
transaction, and use the
transaction.query.undefine()
method:
let databases = DatabaseManager::new(driver);
let db = databases.get(DB_NAME)?;
{
let session = Session::new(db, SessionType::Schema)?;
{
let tx = session.transaction(TransactionType::Write)?;
let undefine_query = "undefine admin sub user;";
tx.query().undefine(undefine_query).resolve()?;
tx.commit().resolve()?;
}
}
Follow the connection guide
to connect the driver
to a TypeDB server, then open a schema
session to the selected database,
open a write
transaction, and use the
transaction.query.undefine()
method:
with driver.session(DB_NAME, SessionType.SCHEMA) as session:
with session.transaction(TransactionType.WRITE) as tx:
undefine_query = "undefine admin sub user;"
tx.query.undefine(undefine_query).resolve()
tx.commit()
Follow the connection guide
to connect the driver
to a TypeDB server, then open a schema
session to the selected database,
open a write
transaction, and use the
transaction.query.undefine()
method:
try {
session = await driver.session(DB_NAME, SessionType.SCHEMA);
try {
tx = await session.transaction(TransactionType.WRITE);
const undefine_query = "undefine admin sub user;";
await tx.query.undefine(undefine_query);
await tx.commit();
}
finally {if (tx.isOpen()) {await tx.close()};}
}
finally {await session?.close();}
Follow the connection guide
to connect the driver
to a TypeDB server, then open a schema
session to the selected database,
open a write
transaction, and use the
transaction.query().undefine()
method:
try (TypeDBSession session = driver.session(DB_NAME, TypeDBSession.Type.SCHEMA)) {
try (TypeDBTransaction tx = session.transaction(TypeDBTransaction.Type.WRITE)) {
String undefineQuery = "undefine admin sub user;";
tx.query().undefine(undefineQuery).resolve();
tx.commit();
}
}
Follow the connection guide
to connect the driver
to a TypeDB server, then open a schema
session to the selected database,
open a write
transaction, and use the
transaction.Query.Undefine()
method:
TypeDBOptions options = new();
using (ITypeDBSession session = driver.Session(DB_NAME, SessionType.Schema)) {
using (ITypeDBTransaction tx = session.Transaction(TransactionType.Write)) {
string undefine_query = "undefine admin sub user;";
tx.Query.Undefine(undefine_query).Resolve();
tx.Commit();
}
}
Follow the connection guide
to connect the driver
to a TypeDB server, then open a schema
session to the selected database,
open a write
transaction, and use the
transaction.query.undefine()
method:
TypeDB::Options options;
TypeDB::Session session = driver.session(DB_NAME, TypeDB::SessionType::SCHEMA, options);
{
TypeDB::Transaction tx = session.transaction(TypeDB::TransactionType::WRITE, options);
std::string undefineQuery = "undefine admin sub user;";
tx.query.undefine(undefineQuery).get();
tx.commit();
}
Follow the connection guide
to connect the driver
to a TypeDB server, then open a schema
session to the selected database,
open a write
transaction, and use the
query_undefine()
function:
Options* opts = options_new();
session = session_new(databaseManager, DB_NAME, Schema, opts);
tx = transaction_new(session, Write, opts);
if (tx == NULL || FAILED()) {
handle_error("Transaction failed to start.");
goto cleanup;
}
char query[512];
snprintf(query, sizeof(query), "undefine admin sub user;");
void_promise_resolve(query_undefine(tx, query, opts));
if (FAILED()) {
handle_error("Query execution failed.");
goto cleanup;
}
void_promise_resolve(transaction_commit(tx));
if (FAILED()) {
handle_error("Transaction commit failed.");
goto cleanup;
}
session_close(session);