> For the complete documentation index, see [llms.txt](https://documentation.astera.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.astera.com/workflows/database-operations/database-delete.md).

# Database Delete

### Overview

The DeleteDatabase object provides functionality to remove data and metadata from a target database. It enables users to drop database tables’ metadata, including primary keys, foreign keys, and indexes, and also truncate tables. The operation can be performed directly on the database or scripted for later execution.

{% hint style="danger" %}
Warning\
Delete operations are destructive. Use transactions and, where appropriate, generate a script for review before execution.
{% endhint %}

### Use Case

A common scenario is cleaning up a target environment before a new data load. For example, a user may truncate staging tables to clear data while retaining structure or drop obsolete tables and constraints after a model change.

### How to Work with DeleteDatabase?

1. From Toolbox > Database Operations, drag DeleteDatabase onto the dataflow designer.

<figure><img src="/files/l61MReXFGAPNh8ubEnkH" alt=""><figcaption><p>01-database-delete-object</p></figcaption></figure>

2. Right‑click on the object and choose Properties. The **Database Delete** Properties window opens.

<figure><img src="/files/y5rHKiB1VgSa1lVFFjiH" alt=""><figcaption><p>02-database-delete-properties-window</p></figcaption></figure>

### Target

#### Target Database Connection *(required)*

Select an existing database connection from the list. This connection must be defined in the project’s **Shared Connections**.

<figure><img src="/files/So4Lio4gNqrjrbVMYT8C" alt=""><figcaption><p>03-target-database-connection</p></figcaption></figure>

#### Target Data Model Path *(optional)*

Specify a data model to limit the scope of the operation to entities relevant to your work. This helps avoid accidental deletion of unrelated objects in shared projects.

#### Data Model View *(enabled when a data model is provided)*

Select a view from the provided data model to further narrow the scope (for example, *Staging*, *Sales*, or *Reference Data*).

<figure><img src="/files/6f0ZUunbd1WKbSY63xq8" alt=""><figcaption><p>04-target-data-model-path-and-view</p></figcaption></figure>

#### Table Names / Entity Names

* If a data model is provided, the field appears as Entity Names.
* If no data model is provided, the field appears as Table Names.

Select specific objects to include. Leave blank to process all entities/tables within scope.

<figure><img src="/files/gb6MRjrxl6MDl6nWjb3K" alt=""><figcaption><p>05-entity/table-names-list</p></figcaption></figure>

### Configuration

#### Action

Determines how the deletion script is handled:

* ExecuteScript — Generate and execute the script directly against the target database.
* WriteScriptToFile — Generate the script and save it to a file for review/approval. When selected, provide Output Script File Path.

<figure><img src="/files/h0bb8JmhfxojHT6cGV43" alt=""><figcaption><p>06-action-configuration</p></figcaption></figure>

#### Use Transaction

Executes all selected operations as a single transaction, where applicable. If any error occurs, the operation is rolled back, preventing partial deletion.

#### Drop Tables

Permanently removes selected tables and their data, along with associated indexes, primary keys, and foreign keys.

#### Drop Primary Keys

Removes primary key constraints from the selected tables, thereby automatically removing all dependent foreign key constraints. Tables remain intact.

#### Drop Foreign Keys

Removes foreign key relationships between tables. Tables and other constraints remain intact.

#### Drop Indexes

Deletes indexes from the selected tables. Useful when decommissioning structures or preparing for schema changes.

#### Truncate Tables

Removes all data from the selected tables while preserving table structure (columns, keys, indexes). Ideal for resetting staging or test data.

{% hint style="info" %}
Note\
Multiple options can be used together. The object generates a single script that performs the selected operations in a safe order.
{% endhint %}

<figure><img src="/files/HopPmqepK0Gj1ihc5Psf" alt=""><figcaption><p>07-deletion-configuration</p></figcaption></figure>

### Config Parameters

Click Next to open the **Config Parameters** window. Parameterization allows dynamic assignment of values at runtime.

<figure><img src="/files/pshxKfXtTr6IbCfwRlf2" alt=""><figcaption><p>08-config-parameters</p></figcaption></figure>

#### Parameter List

* DataModelView — View from the data model used during execution.
* EntityNames — Entities (when a data model is provided) to process.
* TableNames — Tables (when no data model is provided) to process.
* TargetDataModelPath — Path to the data model used for scoping.
* TargetDatabaseConnection — Target database connection to use.
* Configuration.Action — ExecuteScript or WriteScriptToFile.
* Configuration.DropForeignKeys — Boolean; drop foreign keys.
* Configuration.DropPrimaryKeys — Boolean; drop primary keys.
* Configuration.DropIndexes — Boolean; drop indexes.
* Configuration.DropTables — Boolean; drop tables.
* Configuration.OutputScriptFilePath — Script output path (required when writing to file).
* Configuration.TruncateTables — Boolean; truncate tables.
* Configuration.UseTransaction — Boolean; wrap operations in a transaction.

{% hint style="success" %}
Usage Notes\
Use project parameters or external inputs to bind values; ensure paths and connections resolve in the target environment. Boolean parameters should evaluate to True or False.
{% endhint %}

### Best Practices

* Prefer Transactions: Enable Use Transaction to prevent partial changes.
* Review in Sensitive Environments: Use WriteScriptToFile in production and perform peer review.
* Restrict Scope: Use Target Data Model Path and Data Model View to minimize the risk of affecting unrelated objects.
* Backups & Access: Ensure recent backups and proper permissions for drop/truncate operations.
* Understand Impact:
* *Drop Tables* removes structure and data.
* *Truncate Tables* removes only data.
* *Drop Keys/Indexes* alters constraints or performance characteristics without deleting tables.

### Examples

#### Truncate Staging Tables

* Target Database Connection: UAT\_Staging
* Target Data Model Path: RetailModel.Mdl
* Data Model View: Staging
* Entity Names: FactSales\_Stg, DimProduct\_Stg
* Action: ExecuteScript
* Use Transaction: Enabled
* Truncate Tables: Checked

#### Drop Obsolete Tables (Generate Script)

* Target Database Connection: Prod
* Table Names: ArchiveOrders, ArchiveInvoices
* Action: WriteScriptToFile
* Output Script File Path: \\\share\ops\drop\_archive\_tables.sql
* Use Transaction: Enabled
* Drop Tables: Checked

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://documentation.astera.com/workflows/database-operations/database-delete.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
