> ## 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](https://docs.cockroachlabs.com/docs/v24.2/sql-statements) modifies a [stored procedure](https://docs.cockroachlabs.com/docs/v24.2/stored-procedures).

## 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](https://docs.cockroachlabs.com/docs/v24.2/sql-name-resolution) 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](https://docs.cockroachlabs.com/docs/v24.2/security-reference/authorization#supported-privileges) on the schema of the procedure.
* To alter a procedure, a user must [own](https://docs.cockroachlabs.com/docs/v24.2/security-reference/authorization#object-ownership) the procedure.
* To alter a procedure, a user must have [`DROP` privilege](https://docs.cockroachlabs.com/docs/v24.2/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](https://docs.cockroachlabs.com/docs/v24.2/security-reference/authorization#object-ownership) the procedure.
* To alter a procedure, a user must have [`DROP` privilege](https://docs.cockroachlabs.com/docs/v24.2/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](https://docs.cockroachlabs.com/docs/v24.2/sql-name-resolution) of a procedure.

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

#### Required privileges

* To change the schema of a procedure, a user must have [`CREATE` privilege](https://docs.cockroachlabs.com/docs/v24.2/security-reference/authorization#supported-privileges) on the new schema.
* To alter a procedure, a user must [own](https://docs.cockroachlabs.com/docs/v24.2/security-reference/authorization#object-ownership) the procedure.
* To alter a procedure, a user must have [`DROP` privilege](https://docs.cockroachlabs.com/docs/v24.2/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](https://docs.cockroachlabs.com/docs/v24.2/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](https://docs.cockroachlabs.com/docs/v24.2/stored-procedures)
* [PL/pgSQL](https://docs.cockroachlabs.com/docs/v24.2/plpgsql)
* [`CREATE PROCEDURE`](https://docs.cockroachlabs.com/docs/v24.2/create-procedure)
* [`CALL`](https://docs.cockroachlabs.com/docs/v24.2/call)
* [`DROP PROCEDURE`](https://docs.cockroachlabs.com/docs/v24.2/drop-procedure)
