Skip to content

Add documentation on OQL DELETE statement #9765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: "OQL DELETE Statement"
url: /refguide/oql-delete-statement/
beta: true
weight: 210
---

{{% alert color="warning" %}} This feature is experimental. For more information, see [Release Status](/releasenotes/release-status/). {{% /alert %}}

## Introduction

From Mendix version 11.1, you can delete objects in bulk using OQL `DELETE` statements.
These are translated to SQL statements that are sent to the database.
This can be much faster than retrieving the objects and then deleting the resulting list.

This feature is experimental and currently only accessible through the Java API by writing a Java action.

## Java API for OQL updates

OQL Statements can be executed using the `Core.createOqlStatement` Java API. For example:

```java
Core.createOqlStatement("DELETE FROM Module.Customer WHERE Name = 'Mary'").execute(context)
```

You can pass values as parameters to the query. For example:

```java
Core.createOqlStatement("DELETE FROM Module.Customer WHERE Name = $nameParam")
.setVariable("nameParam", customerName)
.execute(context)
```

## `DELETE` Statement syntax

The syntax of `DELETE` statements is:

```sql
DELETE FROM <entity> WHERE <condition>
```

`condition` can be anything that can appear in an OQL [WHERE clause](/refguide/oql-clauses/#where).

### Joins

You cannot directly join other entities in the `FROM` clause. However, you can achieve the same result using long paths or subqueries. For example:

```sql
DELETE FROM Module.Order WHERE Module.Order_Customer/Module.Customer/Name = 'Mary'
```

or

```sql
DELETE FROM Module.Order WHERE ID IN
( SELECT ID FROM Module.Order
INNER JOIN Module.Customer ON Module.Customer/CustomerID = Module.Order/CustomerID
WHERE Module.Customer/Name = 'Mary' )
```

## Limitations

* You cannot use OQL DELETE with entities that have associations with non-default delete behavior. These are associations that use either "Delete as well" or "Delete only if not associated".
* You cannot use OQL DELETE to delete objects of type `System.FileDocument` or any specialization of it.
* Entity access rules are not applied to any OQL statements.
* No event handlers will be executed.
* Runtime and client state will not be updated with the changes.