New ACM paper, free-tier cloud, and open-source license

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:

  1. Use a drop-down list in the top toolbar to select a database.

  2. Switch to schema session and write transaction types.

  3. Open a new tab and insert or type in a Undefine query, for example:

    TypeQL Undefine query
    undefine admin sub user;
  4. Run the query by clicking the Run query button (run).

  5. Commit the changes by clicking the Commit query button (Commit).

Follow the Connect to server guide to connect to TypeDB. Then use the steps below:

  1. Open a schema session and write transaction to the selected database (e.g., sample_db):

    transaction sample_db schema write
  2. Send the Undefine query:

    undefine admin sub user;

    Push Enter twice to send the query.

  3. Commit the changes:

    commit

To send a Undefine query programmatically, use drivers:

  • Rust

  • Python

  • Java

  • Node.js

  • C++

Follow the connection guide to connect the driver to TypeDB Cloud or TypeDB Core, 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 TypeDB Cloud or TypeDB Core, 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 TypeDB Cloud or TypeDB Core, 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 TypeDB Cloud or TypeDB Core, 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 TypeDB Cloud or TypeDB Core, 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();
}

Learn more

Learn more about Undefine queries in TypeQL: syntax, behavior, and query examples.

Learn how to write some data to a database with the schema you just truncated.

Check out the Defining schemas section of our TypeDB Learning course.

Provide Feedback