# Update Method

## Overview

The **Update** method in QueryDeck is used to modify existing records in your database. It allows you to update one or more rows by specifying conditions to match records and providing new values for the desired columns. This method ensures data integrity by enabling you to control which fields are updated and under what conditions.

With the Update method, you can:

* Change specific fields in a record.
* Apply filters to update only matching rows.
* Perform batch updates by modifying multiple records at once.

This method is useful for keeping your data up-to-date and accurately reflecting real-time changes.

## Using the Update Method

1. Select the Base Table

From the left pane, choose the base table you want to update. For this example, we'll use the customers table.

<figure><img src="https://1803924624-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkjtTl1rn3hJ3jyoJt6ty%2Fuploads%2FxChz9dVXjrff8J1Dz9qb%2Fimage.png?alt=media&#x26;token=90416976-259b-4ea7-bf8c-2cc6aa1d5292" alt=""><figcaption></figcaption></figure>

2. Configure the Query Method

In the left pane:

Change the Method to Update.

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%2FH1FmSOqsHWL2D4pGMJud%2Fimage.png?alt=media&#x26;token=a2b6977a-872a-4d74-8e6c-8da849ec523a" alt=""><figcaption></figcaption></figure>

3. Define Update Conditions and Values in the Request

Add the fields you want to update along with their new values.

Define conditions (e.g., filters) to specify which rows should be updated. For instance:

Set active to 0 for customers with last\_name as Smith.

for example :&#x20;

```postman_json
{
    "customer": {
        "active": 1,
        "activebool": true,
        "address_id": 5,
        "create_date": "2006-02-14",
        "email": "mary.smith@sakilacustomer.org",
        "first_name": "Mary",
        "last_name": "xxx",
        "last_update": "2013-05-26 14:49:45",
        "store_id": 1
    }
}
```

This request is to update the last name of mary to "xxx"

4. Save the Endpoint

Click on the Save button in the bottom-left corner of the side pane.

Your update 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%2Fq5J2gEJAWqtTCzxij2s2%2Fimage.png?alt=media&#x26;token=e4152f59-6f04-470b-92d7-90f29132dcfd" 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%2FecFumqNVqx7IheAemuSS%2Fimage.png?alt=media&#x26;token=184e7016-223d-41d3-8961-42b97ddc7f39" alt=""><figcaption></figcaption></figure>

Open Postman:

Paste the endpoint URL into the input field.

Change the request method to PUT.

<figure><img src="https://1803924624-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkjtTl1rn3hJ3jyoJt6ty%2Fuploads%2FLgxHSh3ntcOCNb7dWzcM%2Fimage.png?alt=media&#x26;token=5bcd6a08-9e4a-4fca-bd20-56eebd77a896" alt=""><figcaption></figcaption></figure>

Add a Sample Request Body

Under the Body tab in Postman:

* Select "raw" as the body type.
* Set the "Content-Type" to "application/json".
* Provide the JSON payload in the request body.

<figure><img src="https://1803924624-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkjtTl1rn3hJ3jyoJt6ty%2Fuploads%2FmvybEzjAVNGtLuHbfhBm%2Fimage.png?alt=media&#x26;token=ca04947c-4c68-4e4c-a4ec-87730a6f0b36" alt=""><figcaption></figcaption></figure>

#### Send the Request

* Click on the **Send** button in Postman.
* You will receive a response indicating that the update was successful.

<figure><img src="https://1803924624-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkjtTl1rn3hJ3jyoJt6ty%2Fuploads%2FKsIKv03dlq7Yg7gMmXPM%2Fimage.png?alt=media&#x26;token=9cfe4404-e518-4d8f-a603-ad39b16dfefd" alt=""><figcaption></figcaption></figure>

You have now successfully created and tested your `Update` query.
