PostgreSQL Schema
Schema is the collection of tables.In PostgreSQL, Schema contains data types,indexes, operators, views, sequences, and functions. CREATE SCHEMA command is used to create Schema.
Advantages of using a Schema
1. This allows multiple users to use one database without interfering with each other.
2. To make them more manageable, It organizes database objects into logical groups.
3. To avoid collision between applications, third-party applications can be placed in separate schemas.
Schema Syntax :
The syntax of the Schema statement is −
CREATE SCHEMA schema_name;
Schema Create Table Syntax :
The syntax of the Schema Create Table statement is −
CREATE TABLE lfcschema.lfctable ( ... );
Schema Example :
Let us see an example for creating a schema.
lfcdb=# create schema lfcschema; CREATE SCHEMA \\ the message create schema shows that the schema has been successfully created. -------------------------------------------- \\ let us create a table in the above schema lfcdb=# create table lfcschema.student( ID INT NOT NULL, NAME VARCHAR (20) NOT NULL, AGE INT NOT NULL, ADDRESS CHAR (25), PRIMARY KEY (ID) ); -------------------------------------------- \\This will create an empty table. You can verify the table created by the following command. lfcdb=# select * from lfcschema.student; -------------------------------------------- \\output id | name | age | address | salary ----+------+-----+---------+-------- (0 rows)
Schema DROP Table Syntax :
The syntax of the Schema Drop Table statement is −
DROP SCHEMA lfcschema; ---------------------- DROP SCHEMA lfcschema CASCADE;
Visit :
Discussion