What is Schema?
Have you ever wondered how to work with your fellows in one database without interfering with each other? Is it possible to organize the database objects into logical groups which do not collide with the other objects’ names? We can do those things with Schema: A schema is a collection of tables. A schema also contains views, indexes, sequences, data types, operators, and functions. We support multiple schemas. For example, you can have a database namedoxla and have multiple schemas based on your needs, like auth, model, business, etc.

Default Schema in Oxla
By default, thepublic schema is used in Oxla. When unqualified table_name is used, that table_name is equivalent to public.table_name. It also applies to CREATE, DROP, and SELECT TABLE statements.
Furthermore, you can create multiple schemas per your needs.
Schema Usage Scenarios
1. Create a Schema
The basic syntax of creating a schema is as follows:- schema_nameis the schema name you are going to create.
- IF NOT EXISTSis an optional parameter to avoid errors if the schema already exists.
2. Create a Table in Schema
The syntax to create a table in a specified schema is as follows:- schema_nameis the schema that you have created.
- table_nameis the table name you are going to create.
3. Select a Table in Schema
After creating the table and inserting some data, display all rows with the syntax below:- schema_nameis the name of the schema.
- table_nameis the name of the table you want to display.
4. Drop the Schema
Option 1: To drop an empty schema where no objects remain in it, use the command below:- schema_nameis the schema name you are going to create.
- IF EXISTSis an optional parameter to avoid errors if the schema does not exist.
Examples
Creating Schema
- First, connect to Oxla and create a schema as shown below:
- Next, create a table in the above schema with the following details:
- You can verify and show the table made with the command below:
- You will get the following result:
Creating Schema Using IF NOT EXISTS
To avoid errors when the schema already exists, use theIF NOT EXISTS option. Here is how it works:
Example without IF NOT EXISTS
- First, create the schema without using the IF NOT EXISTSoption.
- If you attempt to create the schema again without using IF NOT EXISTS, it will result in an error.
Example with IF NOT EXISTS
Now, create the schema using theIF NOT EXISTS option to avoid the error.
IF NOT EXISTS allows the query to create a schema even if it already exists.
Dropping Schema
Use the command below to delete the schema and also the tables in it.Dropping Schema using IF EXISTS
Example without IF EXISTS
- First, drop the schema without using the IF EXISTSoption.
- If you attempt to drop the schema again without using IF EXISTS, it will result in an error.
Example with IF EXISTS
Now, drop the schema using theIF EXISTS option.
IF EXISTS allows the query to succeed even if the schema does not exist.
