Creating Schema

SCHEMA :
Schema is a named space that contains named objects such as tables, datatypes, functions and operators. A schema can also contain views, indexes, sequences.

One database can have multiple schema. A schema helps in separation of data between different application. Assume we have a production database which has different department such as HR,Finance, transport, manufacturing and all the departments are accessing the Production database.

Here we can create a schema where we can include all the table belonging to HR dept, by that way when we need a backup we can take the particular schema backup alone rather than taking full DB backup.

In one databse we can have multiple users accessing multiple schema without interfering with each other. There are several reasons why one might want to use schemas:
  1. To allow many users to use one database without interfering with each others.
  2. To organize database objects into logical groups to make them more manageable.
  3. Third-party applications can be put into separate schemas so they do not collide with the names of other objects.
Step to create schema in Postgresql :
    Syntax :  create schema < schema name >;

List out the schemas
    postgres=# \dn

    List of schemas
    Name  |  Owner   
    --------+----------
    public | postgres
    (1 row)

    postgres=# create schema s1;

    CREATE SCHEMA
    postgres=# \dn;

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


(Creating table inside schema)