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

# ALTER PROCEDURE

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 PROCEDURE` <InternalLink path="sql-statements">statement</InternalLink> modifies a <InternalLink path="stored-procedures">stored procedure</InternalLink>.

## Required privileges

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

## Synopsis

<img src="https://mintcdn.com/cockroachlabs/9gyQKEP-CuQuCsI3/images/sql-diagrams/v25.3/alter_proc.svg?fit=max&auto=format&n=9gyQKEP-CuQuCsI3&q=85&s=2aeeecfcd35429982e340c79a58db3e8" alt="alter_proc syntax diagram" style={{maxWidth: "100%", overflowX: "auto"}} width="695" height="267" data-path="images/sql-diagrams/v25.3/alter_proc.svg" />

## 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 <InternalLink path="sql-name-resolution">schema</InternalLink> 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 <InternalLink path="security-reference/authorization#supported-privileges">`CREATE` privilege</InternalLink> on the schema of the procedure.
* To alter a procedure, a user must <InternalLink path="security-reference/authorization#object-ownership">own</InternalLink> the procedure.
* To alter a procedure, a user must have <InternalLink path="security-reference/authorization#supported-privileges">`DROP` privilege</InternalLink> 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 <InternalLink path="security-reference/authorization#object-ownership">own</InternalLink> the procedure.
* To alter a procedure, a user must have <InternalLink path="security-reference/authorization#supported-privileges">`DROP` privilege</InternalLink> 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 <InternalLink path="sql-name-resolution">schema</InternalLink> of a procedure.

<Note>
  CockroachDB supports `SET SCHEMA` as an <InternalLink path="set-vars#supported-variables">alias for setting the `search_path` session variable</InternalLink>.
</Note>

#### Required privileges

* To change the schema of a procedure, a user must have <InternalLink path="security-reference/authorization#supported-privileges">`CREATE` privilege</InternalLink> on the new schema.
* To alter a procedure, a user must <InternalLink path="security-reference/authorization#object-ownership">own</InternalLink> the procedure.
* To alter a procedure, a user must have <InternalLink path="security-reference/authorization#supported-privileges">`DROP` privilege</InternalLink> 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 <InternalLink path="stored-procedures">`delete_earliest_histories` example procedure</InternalLink> to `delete_histories`:

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

## See also

* <InternalLink path="stored-procedures">Stored Procedures</InternalLink>
* <InternalLink path="plpgsql">PL/pgSQL</InternalLink>
* <InternalLink path="create-procedure">`CREATE PROCEDURE`</InternalLink>
* <InternalLink path="call">`CALL`</InternalLink>
* <InternalLink path="drop-procedure">`DROP PROCEDURE`</InternalLink>
