You are on page 1of 7

ACADEMY

Schemas

1
Object hierarchy

– Schemas belong to users or roles


– Schemas contain objects:
– Tables and Views
– Functions and Scripts
– Objects within schemas belong to schema owner
– Access to schemas or single objects is controlled with object privileges
Database

Root-
User Role Connection
Catalog

Object System System Object


Schema
privileges privileges privileges privileges

Table View Function Script

Object Object Object Object


Constraints
privileges privileges privileges privileges

2 Schemas ACADEMY

Object hierarchy

A schema belongs to a user or a role


A schema contains objects:
Tables and Views
Functions and Scripts
All objects of a schema belong to the owner of the schema
Access to schemas or single schema objects can be controlled
by granting object privileges
Manage schemas

– Creating a new schema

CREATE SCHEMA [IF NOT EXISTS] <schema_name>;

– Newly created schema is automatically opened in that session


– Creator of the schema is owner

– Schema owner can be changed


ALTER SCHEMA <schema_name> CHANGE OWNER <user_or_role>;

– Dropping schemas

DROP SCHEMA [IF EXISTS] <schema_name> [CASCADE];

3 Schemas ACADEMY

Manage schemas

Schemas are created with the CREATE SCHEMA command.


A newly created schema is automatically set as CURRENT_SCHEMA for name resolution in
the session where the schema was created.
The creator of the schema is owner. This owner can be changed afterwards with the ALTER
SCHEMA command.
The DROP SCHEMA command can be used to drop schemas. The CASCADE clause is required
if there are objects inside that schema.
Schemas and objects

– Database objects are in a schema


– except Users, Roles and Connections

– Schema prefix usage:


SELECT * FROM s1.tab1;

– No prefix needed inside the schema:


OPEN SCHEMA s1;
SELECT * FROM tab1;

5 Schemas ACADEMY

Schemas and objects

Via qualified identifiers you can reference objects in any schema.


A schema can be activated/opened to allow non-qualified identifiers.
System schemas

– No schema prefix needed

– Schema SYS
– Metadata
– current system status
SELECT * FROM SYS.EXA_ALL_OBJECTS;
SELECT * FROM EXA_ALL_OBJECTS;

– Schema EXA_STATISTICS
– Statistical metadata
– Resource usage
– Database status
SELECT * FROM EXA_STATISTICS.EXA_DB_SIZE_LAST_DAY;
SELECT * FROM EXA_DB_SIZE_LAST_DAY;

6 Schemas ACADEMY

System schemas

They are integrated in the current namespace, so no prefix is needed to access them from
any schema.

The schema SYS contains metadata and the current system status.

The schema EXA_STATISTIC contains information about statistical metadata,


Resource usage and database status.
Metainfo about Schemas

– EXA_SCHEMAS
– List of all existing schemas of the database
– Available for all users
– Important columns: SCHEMA_NAME, SCHEMA_OWNER

– EXA_SCHEMA_OBJECTS
– List of all objects in the currently opened schema
– Available for all users
– Important columns: OBJECT_NAME, OBJECT_TYPE
– Types: TABLE | VIEW | FUNCTION | SCRIPT

7 Schemas ACADEMY

Metainfo about Schemas

EXA_SCHEMAS and EXA_SCHEMA_OBJECTS contain metainformation about Exasol schemas


and can be accessed by every user.
Virtual schemas
– Allow convenient access to arbitrary data sources
– Like a read-only link to an external source
– Contain tables that look like regular tables
– Their data is not locally stored
– They can be used in SQL queries and joined with regular tables Data Warehouse
1

Virtual Schema

ETL Online Access

8 Schemas ACADEMY

Virtual schemas

Virtual schemas provide an abstraction to conveniently access arbitrary data sources.


Virtual schemas are a kind of read-only link to an external source.
A virtual schema contains virtual tables which look like regular tables except that the
actual data is not stored locally.
Those tables can be used in SQL queries and even combined with persistent tables or other
virtual tables.

You might also like