Create schema in PostgreSQL

Schema is nothing to separate groups of tables into their own names. Schema is database specific. Single schema can be present in multiple database in PostgreSQL.

Syntax:

CREATE SCHEMA schema_name;

Examples:

CREATE SCHEMA finance; CREATE SCHEMA HR; CREATE SCHEMA sales; CREATE SCHEMA transport; CREATE SCHEMA accounts;

To get list of schemas in PostgreSQL:

select schema_name from information_schema.schemata;

Ouput:

schema_name
——————–
pg_toast
pg_temp_1
pg_toast_temp_1
pg_catalog
public
information_schema
practice
hr
sales
transport
finance

To get current schema:

select current_schema;

How to switch schema in PostgreSQL

SET search_path to accounts;

How to create table in particular schema?

Switch to schema and then create table or Create table with the following syntax

create table accounts.account(acno int, name varchar(50));

Related Posts

CheapSexCams
Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Powered by k2schools
%d bloggers like this: