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

# CREATE SCHEMA

Use the CREATE SCHEMA statement to create schema in the current database.

## Synopsis

Use the `CREATE SCHEMA` statement to create a schema in the current database. A schema is essentially a namespace: it contains named objects (tables, data types, functions, and operators) whose names can duplicate those of objects in other schemas. Named objects in a schema can be accessed by using the schema name as prefix or by setting the schema name in the search path.

## Syntax

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

```output.ebnf
create_schema_name ::= CREATE SCHEMA [ IF NOT EXISTS ] schema_name 
                       [ AUTHORIZATION role_specification ]

create_schema_role ::= CREATE SCHEMA [ IF NOT EXISTS ] AUTHORIZATION 
                       role_specification

role_specification ::= role_name | CURRENT_USER | SESSION_USER
```

#### create\_schema\_name

CREATESCHEMAIFNOTEXISTS[schema\_name](/stable/api/ysql/syntax_resources/grammar_diagrams#schema-name)AUTHORIZATION[role\_specification](#role-specification)

#### create\_schema\_role

CREATESCHEMAIFNOTEXISTSAUTHORIZATION[role\_specification](#role-specification)

#### role\_specification

[role\_name](/stable/api/ysql/syntax_resources/grammar_diagrams#role-name)CURRENT\_USERSESSION\_USER

Where

- `schema_name` is the name of the schema being created. If no schema\_name is specified, the `role_name` is used. 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.
- `role_name` is the role who will own the new schema. If omitted, it defaults to the user executing the command. To create a schema owned by another role, you must be a direct or indirect member of that role, or be a superuser.

## Examples

- Create a schema.

```plpgsql
yugabyte=# CREATE SCHEMA IF NOT EXISTS branch;
```

- Create a schema for a user.

```plpgsql
yugabyte=# CREATE ROLE John;
yugabyte=# CREATE SCHEMA AUTHORIZATION john;
```

- Create a schema that will be owned by another role.

```plpgsql
yugabyte=# CREATE SCHEMA branch AUTHORIZATION john;
```

## See also

- [DROP SCHEMA](/stable/api/ysql/the-sql-language/statements/ddl_drop_schema "DROP SCHEMA")
- [ALTER SCHEMA](/stable/api/ysql/the-sql-language/statements/ddl_alter_schema "ALTER SCHEMA")
- [CREATE TABLE](/stable/api/ysql/the-sql-language/statements/ddl_create_table "CREATE TABLE")
- [CREATE VIEW](/stable/api/ysql/the-sql-language/statements/ddl_create_view "CREATE VIEW")
- [CREATE INDEX](/stable/api/ysql/the-sql-language/statements/ddl_create_index/ "CREATE INDEX")
- [CREATE SEQUENCE](/stable/api/ysql/the-sql-language/statements/ddl_create_sequence "CREATE SEQUENCE")
- [GRANT](/stable/api/ysql/the-sql-language/statements/dcl_grant "GRANT")
