In SQL, a schema acts as an organizational container that separates objects into logical groups, similar to folders in a file system. A single database can hold many schemas, allowing different teams, modules or applications to work in isolation while sharing the same physical database instance. Object names are qualified by schema (schema_name.table_name) which prevents naming collisions and improves clarity.Most databases expose three main statements that use the SCHEMA keyword:• CREATE SCHEMA – creates a new empty namespace, optionally owned by a specific role and optionally populated with objects created in the same statement.• ALTER SCHEMA – changes properties such as the schema name or moves existing objects into/out of the schema (support varies by vendor).• DROP SCHEMA – removes the namespace; most engines allow CASCADE to drop contained objects or RESTRICT to block the drop when objects exist.Within a session you can set the default search path (for example, PostgreSQL SET search_path) so unqualified object names resolve to the intended schema. MySQL treats SCHEMA as a synonym for DATABASE, but other engines distinguish the two. SQLite does not implement schemas. Oracle uses the term schema interchangeably with user because each user owns one schema.Caveats• Permissions are usually granted at the schema and object level separately – creating a schema does not automatically give all users access to the objects inside.• Dropping a schema with CASCADE is irreversible and deletes every object it contains.• In cross-database queries, fully qualify objects with database.schema.table to avoid ambiguity.
schema_name
(identifier) - Name of the schema to operate onIF NOT EXISTS
(clause) - Prevents error if schema already exists (CREATE)AUTHORIZATION
(identifier) - Role that will own the new schema (CREATE)CASCADE
(clause) - Drop dependent objects automatically (DROP)RESTRICT
(clause) - Refuse drop if dependents exist (DROP)SQL-92
A schema is a logical namespace inside a database that groups related objects so they can be referenced and secured together.
Use CREATE SCHEMA schema_name AUTHORIZATION role_name; This makes role_name the owner and controller of objects in that schema.
The database deletes the schema and every object it contains. This operation is irreversible and should be used with caution.
No. SQLite has a single default namespace, so statements like CREATE SCHEMA are not recognized.