The PostgreSQL schema (SCHEMA) can look like a collection of tables.
A schema can contain views, indexes, data types, functions, operators, and so on.
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 using patterns:
Allow multiple users to use a database without interfering with each other.
Organize database objects into logical groups for easier management.
Objects applied by third parties can be placed in separate schemas so that they do not conflict with the names of other objects.
Patterns are similar to directories at the operating system layer, but patterns cannot be nested. We can use it. CREATE SCHEMA Statement to create a pattern, the syntax format is as follows: Next we connect to runoobdb to create the schema myschema: The output “CREATE SCHEMA” indicates that the schema was created successfully. Next let’s create another table: The above command creates an empty table, and we use the following SQL to see if the table is created: Delete an empty schema (where all objects have been deleted): Delete a schema and all objects contained in it: 5.12.1. Grammar ¶
CREATE SCHEMA myschema.mytable (
...
);
5.12.2. Example ¶
runoobdb=# create schema myschema;
CREATE SCHEMA
runoobdb=# 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)
);
runoobdb=# select * from myschema.company;
id | name | age | address | salary
----+------+-----+---------+--------
(0 rows)
5.12.3. Delete Mod ¶
DROP SCHEMA myschema;
DROP SCHEMA myschema CASCADE;