WEB DEVELOPER SITE
PHP7
 

PostgreSQL mode (SCHEMA)


PostgreSQL mode (SCHEMA) can be viewed as a collection of tables.

A schema can contain views, indexes, data types, functions, operators, and more.

The same object name can be used in different schemas without conflicts, for example both schema1 and myschema can contain a table named mytable.

Advantages of usage patterns:

  • Allow multiple users to use one database and not interfere with each other.

  • Organize database objects into logical groups for easier management.

  • Objects for third-party applications can be placed in separate schemas so they don't conflict with the names of other objects.

The pattern is similar to the directory of the operating system layer, but the patterns cannot be nested.

Syntax

We can use the CREATE SCHEMA statement to create a pattern with the following syntax:

CREATE TABLE myschema.mytable (
...
);

Instance

Next we connect to welookupsdb to create the pattern myschema:

welookupsdb=# create schema Myschema;
CREATE SCHEMA

Output result "CREATE SCHEMA" means that the pattern was created successfully.

Next we will create another form:

welookupsdb=# create table Myschema.company(
   ID INT NOT NULL,
   NAME VARCHAR (20) NOT NULL,
   AGE INT NOT NULL,
   ADDRESS CHAR (25),
   SALARY DECIMAL (18, 2),
   PRIMARY KEY (ID)
);

The above command creates an empty form, and we use the following SQL to see if the form was created:

welookupsdb=# select * from myschema.company ;
 Id | name | age | address |salary
----+------+-----+---------+--------
(0rows)

Delete mode

Delete an empty mode (all objects have been deleted):

DROP SCHEMA myschema;

Delete a pattern and all the objects it contains: