> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cockroachlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ALTER TRIGGER

The `ALTER TRIGGER` [statement](/docs/stable/sql-statements.md) modifies a [trigger](/docs/stable/triggers.md).

## Required privileges

To rename a trigger, the user must be the owner of the table on which the trigger is defined.

## Synopsis

![alter\_trigger syntax diagram](https://mintcdn.com/cockroachlabs/VQ_w3c6MHYdiS7Tn/images/sql-diagrams/common/alter_trigger.svg?fit=max\&auto=format\&n=VQ_w3c6MHYdiS7Tn\&q=85\&s=b79242ea61963f60427747aa13c1c9b2)

## Parameters

| Parameter | Description |
| - | - |
| `IF EXISTS` | Rename the trigger only if the table and trigger exist. If the table or trigger does not exist, the statement succeeds without renaming a trigger. |
| `trigger_name` | The current name of the trigger. |
| `table_name` | The name of the table associated with the trigger. |
| `trigger_new_name` | The new name of the trigger. |

> [!NOTE]
>
> `ALTER TRIGGER ... IF EXISTS` is a CockroachDB extension of the PostgreSQL syntax, which does not accept `IF EXISTS` for `ALTER TRIGGER`.

Renaming a trigger to its current name succeeds without changes. Renaming a trigger to a name that is already used by another trigger on the same table returns a duplicate-object error.

## Examples

#### Setup

To follow along, run [`cockroach demo`](/docs/stable/cockroach-demo) to start a temporary, in-memory cluster with the [`movr`](/docs/stable/movr) sample dataset preloaded:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ cockroach demo
```

### Rename a trigger

Create a sample trigger function:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
CREATE FUNCTION update_timestamp()
RETURNS TRIGGER AS $$
BEGIN
  RAISE NOTICE 'Current timestamp: %', now();
  RETURN NEW;
END;
$$ LANGUAGE PLpgSQL;
```

Create a sample trigger:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
CREATE TRIGGER log_update_timestamp
AFTER UPDATE ON users
FOR EACH ROW
EXECUTE FUNCTION update_timestamp();
```

Rename the trigger:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
ALTER TRIGGER log_update_timestamp ON users RENAME TO log_updates;
```

Verify the new trigger name:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SHOW TRIGGERS FROM users;
```

```
  trigger_name | enabled
---------------+----------
  log_updates  |    t
(1 row)
```

## See also

* [Triggers](/docs/stable/triggers.md)
* [`CREATE TRIGGER`](/docs/stable/create-trigger)
* [`DROP TRIGGER`](/docs/stable/drop-trigger)
* [`SHOW TRIGGERS`](/docs/stable/show-triggers)
* [`SHOW CREATE`](/docs/stable/show-create)
* [`CREATE FUNCTION`](/docs/stable/create-function)
