Skip to main content

What is a "schema" in SQL?

A schema in SQL is a logical space (container) that holds database objects: tables, views, functions, triggers, and so on.

It helps organize the database's structure and separate data by meaning or by user.

Example

sql
CREATE SCHEMA accounting; CREATE TABLE accounting.invoices ( id INT, amount DECIMAL );

Here the invoices table lives inside the accounting schema.

The advantages of schemas

  1. Order, objects don't get mixed into one pile.
  2. Security, you can grant access to individual schemas instead of the whole database.
  3. Convenience, schemas work like "folders" inside a database.

So a schema is like a folder for tables and other objects, helping keep the database in order.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.