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

The `ALTER PROCEDURE` [statement](/docs/stable/sql-statements.md) modifies a [stored procedure](/docs/stable/stored-procedures.md).

## Required privileges

Refer to the respective [subcommands](#subcommands).

## Synopsis

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

## Parameters

| Parameter | Description |
| - | - |
| `proc_name` | The name of the procedure to alter. |
| `routine_param` | An optional list of procedure parameters. |

## Subcommands

| Subcommand | Description |
| - | - |
| [`OWNER TO`](#owner-to) | Change the owner of a procedure. |
| [`RENAME TO`](#rename-to) | Change the name of a procedure. |
| [`SET SCHEMA`](#set-schema) | Change the [schema](/docs/stable/sql-name-resolution.md) of a procedure. |

### `OWNER TO`

`ALTER PROCEDURE ... OWNER TO` is used to change the owner of a procedure.

#### Required privileges

* To alter the owner of a procedure, the new owner must have [`CREATE` privilege](/docs/stable/security-reference/authorization#supported-privileges) on the schema of the procedure.
* To alter a procedure, a user must [own](/docs/stable/security-reference/authorization.md#object-ownership) the procedure.
* To alter a procedure, a user must have [`DROP` privilege](/docs/stable/security-reference/authorization#supported-privileges) on the schema of the procedure.

#### Parameters

| Parameter | Description |
| - | - |
| `role_spec` | The role to set as the owner of the procedure. |

See [Synopsis](#synopsis).

### `RENAME TO`

`ALTER PROCEDURE ... RENAME TO` changes the name of a procedure.

#### Required privileges

* To alter a procedure, a user must [own](/docs/stable/security-reference/authorization.md#object-ownership) the procedure.
* To alter a procedure, a user must have [`DROP` privilege](/docs/stable/security-reference/authorization#supported-privileges) on the schema of the procedure.

#### Parameters

| Parameter | Description |
| - | - |
| `proc_new_name` | The new name of the procedure. |

See [Synopsis](#synopsis).

### `SET SCHEMA`

`ALTER PROCEDURE ... SET SCHEMA` changes the [schema](/docs/stable/sql-name-resolution.md) of a procedure.

> [!NOTE]
>
> CockroachDB supports `SET SCHEMA` as an [alias for setting the `search_path` session variable](/docs/stable/set-vars#supported-variables).

#### Required privileges

* To change the schema of a procedure, a user must have [`CREATE` privilege](/docs/stable/security-reference/authorization#supported-privileges) on the new schema.
* To alter a procedure, a user must [own](/docs/stable/security-reference/authorization.md#object-ownership) the procedure.
* To alter a procedure, a user must have [`DROP` privilege](/docs/stable/security-reference/authorization#supported-privileges) on the schema of the procedure.

#### Parameters

| Parameter | Description |
| - | - |
| `schema_name` | The name of the new schema for the procedure. |

See [Synopsis](#synopsis).

## Examples

### Rename a stored procedure

The following statement renames the [`delete_earliest_histories` example procedure](/docs/stable/stored-procedures) to `delete_histories`:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
ALTER PROCEDURE delete_earliest_histories RENAME TO delete_histories;
```

## See also

* [Stored Procedures](/docs/stable/stored-procedures.md)
* [PL/pgSQL](/docs/stable/plpgsql.md)
* [`CREATE PROCEDURE`](/docs/stable/create-procedure)
* [`CALL`](/docs/stable/call)
* [`DROP PROCEDURE`](/docs/stable/drop-procedure)
