> ## 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

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

The `ALTER TRIGGER` <InternalLink path="sql-statements">statement</InternalLink> modifies a <InternalLink path="triggers">trigger</InternalLink>.

## Required privileges

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

## Synopsis

<img src="https://mintcdn.com/cockroachlabs/xAVQSiE1unzqunvY/images/sql-diagrams/v26.3/alter_trigger.svg?fit=max&auto=format&n=xAVQSiE1unzqunvY&q=85&s=48d0e0f63b21104cff5112e35500f62b" alt="alter_trigger syntax diagram" style={{maxWidth: "100%", overflowX: "auto"}} width="701" height="135" data-path="images/sql-diagrams/v26.3/alter_trigger.svg" />

## 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`.
</Note>

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 <InternalLink path="cockroach-demo">`cockroach demo`</InternalLink> to start a temporary, in-memory cluster with the <InternalLink path="movr">`movr`</InternalLink> 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

* <InternalLink path="triggers">Triggers</InternalLink>
* <InternalLink path="create-trigger">`CREATE TRIGGER`</InternalLink>
* <InternalLink path="drop-trigger">`DROP TRIGGER`</InternalLink>
* <InternalLink path="show-triggers">`SHOW TRIGGERS`</InternalLink>
* <InternalLink path="show-create">`SHOW CREATE`</InternalLink>
* <InternalLink path="create-function">`CREATE FUNCTION`</InternalLink>
