PostgreSQL CREATE SCHEMA

CREATE SCHEMA
Creating a schema using command:
Syntax:

CREATE SCHEMA name;  

Parameters:
name: It is used to specify the name of the database to be created.

Example:

CREATE SCHEMA students;

Explanation:
A new schema will be created with the name ‘students’.

Creating a schema using UI:
To create a schema in PostgreSQL using pgAdmin, follow the below steps.

  • Go to start menu.
  • Open pgAdmin.
  • Connect PostgreSQL to the localhost server.
  • Click on the plus icon to expand the databases.
  • Expand the selected database.
  • Right-click on the selected database.
  • Click on the “New schema” to create a new schema.
  • Add a name to the created schema.

 

PostgreSQL Create Table in Schema:

To create a table in a schema in PostgreSQL, follow the below steps.

  • Expand the selected schema.
  • Right-click on the selected table.
  • Click on the “New Table” to create a new table.
  • To add columns, click on the “Columns” and ADD buttons.

 

Drop PostgreSQL Schema:

To drop or eliminate a schema in PostgreSQL, follow the below steps.

  • Click on the schema.
  • Right-click on the selected schema.
  • You will see the following page.
  • Click on the Drop option.
  • Click on the “Yes” button.
  • If there is an ERROR while dropping, drop the dependent object first.
  • Right-click on the selected schema.
  • Click on the “Drop cascaded”.
  • Click “Yes” to delete the dependent objects.
  • On deleting the dependent objects the schema will be automatically deleted.

 

Advantages of using a Schema:

A schema add a lot of benefits for the users, and thus is highly recommended. Some of these advantages are:

  • It facilitates multiple users to use one database without interfering with each other.
  • To make the Database objects more manageable, they are organized into logical groups.
  • To avoid collision with the names of other objects, the third party schemas can be put into separate schemas.