# Delete Method

## Overview

The `Delete` method allows you to remove rows from a table based on specified conditions.&#x20;

## Using the Delete Method

#### 1. Select the Base Table

* From the left pane in the demo app, choose the base table where you want to delete rows. For this example, we'll use the `role_types` table.

<figure><img src="https://1803924624-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkjtTl1rn3hJ3jyoJt6ty%2Fuploads%2FqwOHM5V2dtQOEGw5ISpN%2Fimage.png?alt=media&#x26;token=0b4d6e2e-791b-4a67-b621-40da9c0ba0ca" alt=""><figcaption></figcaption></figure>

2\. Configure the Query Method

* In the left pane:
  * Change the **Method** to `Delete`.
  * Update the **Route Name** if required.

<figure><img src="https://1803924624-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkjtTl1rn3hJ3jyoJt6ty%2Fuploads%2FOWdMHeT5nbGU5y38FFqJ%2Fimage.png?alt=media&#x26;token=c05cb0cc-d630-40cd-ba99-0576703d69d2" alt=""><figcaption></figcaption></figure>

#### 3. Define Deletion Conditions

* Add filters by clicking on the corresponding button on the side pane, to specify which rows should be deleted.&#x20;

<figure><img src="https://1803924624-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkjtTl1rn3hJ3jyoJt6ty%2Fuploads%2Feu5Z2qYGdtXlZ3wUIIM2%2Fimage.png?alt=media&#x26;token=4867ba5f-f639-4628-9cd5-feb4141baee6" alt=""><figcaption></figcaption></figure>

* For example:
  * Delete all customers where `roll_type_id` is `:role_type_id`(as provided by the user in the URL)
* These conditions will ensure that only the intended rows are removed.&#x20;

<figure><img src="https://1803924624-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkjtTl1rn3hJ3jyoJt6ty%2Fuploads%2FiYKmaAxGQuktGcn8Mu5q%2Fimage.png?alt=media&#x26;token=7cdbfc89-67f6-4476-80ce-8cf0179e6dd5" alt=""><figcaption></figcaption></figure>

#### 4. Save the Endpoint

* Click on the **Save** button in the bottom-left corner.
* Your delete query endpoint is now ready.

<figure><img src="https://1803924624-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkjtTl1rn3hJ3jyoJt6ty%2Fuploads%2FQiPPYZfGxg1BeQBMZ5d9%2Fimage.png?alt=media&#x26;token=55ae6835-e91b-4fac-96f1-db69e0112254" alt=""><figcaption></figcaption></figure>

## Testing

* Copy the endpoint URL by clicking on **Request**.

<figure><img src="https://1803924624-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkjtTl1rn3hJ3jyoJt6ty%2Fuploads%2F5zS1Ttjjfu4zN9a4Vmbq%2Fimage.png?alt=media&#x26;token=a42b15a7-76d8-4850-945c-d3ec988601f5" alt=""><figcaption></figcaption></figure>

* Open **Postman**:
  * Paste the endpoint URL into the input field.
  * Change the request method to `DELETE`.
  * add the required role\_type\_id at the end of the URL

<figure><img src="https://1803924624-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkjtTl1rn3hJ3jyoJt6ty%2Fuploads%2FhEOaeAIVSwgrJJxdlRz6%2Fimage.png?alt=media&#x26;token=14acecdc-ac2c-4e6b-b5af-f7473ce72dba" alt=""><figcaption></figcaption></figure>

&#x20;Add a Sample Request Body (if applicable)

* Under the **Body** tab in Postman:
  * Select **raw** as the body type.
  * Paste a sample request body in JSON format, specifying the filters for deletion. (Here we aren't doing this)
* Note: If your API supports conditionless deletion (deleting all rows), ensure you proceed with caution and verify your intent.

#### Send the Request

* Click on the **Send** button in Postman.

<figure><img src="https://1803924624-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkjtTl1rn3hJ3jyoJt6ty%2Fuploads%2FrSMCpEWszswZxOvfPH86%2Fimage.png?alt=media&#x26;token=ec0f33c2-b5e2-46e5-a376-7b517cc9562d" alt=""><figcaption></figcaption></figure>

* You will receive a response indicating the deletion status.&#x20;

<figure><img src="https://1803924624-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkjtTl1rn3hJ3jyoJt6ty%2Fuploads%2FFRgU5u0n6AQNCrVdab6f%2Fimage.png?alt=media&#x26;token=17392380-cad1-4df6-80f1-f98f41678ee2" alt=""><figcaption></figcaption></figure>

In this example, all rows in the `role_types` table where `role_type_id` is a38ea91f-b0d8-4ece-8fc3-701fbd8980c1 will be removed.

***

### Precautions

1. **Test Your Query**:
   * Always test your `Delete` query on a non-production environment to ensure that the filters work as intended.
2. **Use Filters**:
   * Avoid running conditionless `Delete` queries to prevent accidental removal of all rows.
3. **Backup Your Data**:
   * Ensure you have a backup of your data before executing `Delete` queries in a production environment.

***

You have now successfully created and tested a `Delete` query in QueryDeck. Continue exploring other methods to build robust API solutions!
