---
title: "ALTER SCHEMA"
url: "https://docs.yugabyte.com/stable/api/ysql/the-sql-language/statements/ddl_alter_schema/"
---

# ALTER SCHEMA

Use the ALTER SCHEMA statement to change the definition of a schema.

## Synopsis

Use the `ALTER SCHEMA` statement to change the definition of a schema.

## Syntax

- [![Grammar Icon](/icons/file-lines.svg)Grammar](#grammar-2)
- [![Diagram Icon](/icons/diagram.svg)Diagram](#diagram-2)

```output.ebnf
alter_schema ::= ALTER SCHEMA schema_name 
                 { RENAME TO new_name
                   | OWNER TO { new_owner
                                | CURRENT_USER
                                | SESSION_USER } }
```

#### alter\_schema

ALTERSCHEMA[schema\_name](/stable/api/ysql/syntax_resources/grammar_diagrams#schema-name)RENAMETO[new\_name](/stable/api/ysql/syntax_resources/grammar_diagrams#new-name)OWNERTO[new\_owner](/stable/api/ysql/syntax_resources/grammar_diagrams#new-owner)CURRENT\_USERSESSION\_USER

## Semantics

- ALTER SCHEMA changes the definition of a schema.
- In order to use `ALTER SCHEMA`, you need to be the owner of the schema.
- Renaming a schema requires having the `CREATE` privilege for the database.
- If you want to change the owner, you must also be a direct or indirect member of the new owning role, and you need to have the `CREATE` privilege for the database. (It's worth noting that superusers possess these privileges by default.)

### *alter\_schema*

#### ALTER SCHEMA *schema\_name*

Specify the name of the schema (*schema\_name*). An error is raised if a schema with that name does not exist in the current database.

#### schema\_name

The name of the schema.

#### RENAME TO *new\_name*

Rename the schema.

#### new\_name

Schema names must not begin with `pg_`. The attempt to create a schema with such a name, or to rename an existing schema to have such a name, causes an error.

#### OWNER TO (*new\_owner* | *CURRENT\_USER* | *SESSION\_USER*)

Change the owner of the schema.

#### new\_owner

The new owner of the schema.

#### CURRENT\_USER

Username of current execution context.

#### SESSION\_USER

Username of current session.

## Examples

Create a simple schema.

```plpgsql
yugabyte=# CREATE SCHEMA schema22;
```

```
CREATE SCHEMA
```

Rename the schema.

```plpgsql
yugabyte=# ALTER SCHEMA schema22 RENAME TO schema25;
```

```
ALTER SCHEMA
```

```plpgsql
yugabyte=# \dn
```

```
   List of schemas
   Name   |  Owner
----------+----------
 public   | postgres
 schema25 | yugabyte
(2 rows)
```

Change the owner of the schema.

```plpgsql
yugabyte=# ALTER SCHEMA schema25 OWNER TO postgres;
```

```
ALTER SCHEMA
```

```plpgsql
yugabyte=# \dn
```

```
   List of schemas
   Name   |  Owner
----------+----------
 public   | postgres
 schema25 | postgres
(2 rows)
```

## See also

- [CREATE SCHEMA](/stable/api/ysql/the-sql-language/statements/ddl_create_schema "CREATE SCHEMA")
- [DROP SCHEMA](/stable/api/ysql/the-sql-language/statements/ddl_drop_schema "DROP SCHEMA")
