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
- Order, objects don't get mixed into one pile.
- Security, you can grant access to individual schemas instead of the whole database.
- 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 readyPremium
A concise answer to help you respond confidently on this topic during an interview.