A database schema is the blueprint or architecture of a database. It defines how data is organized, structured, and related within the system.

What Does a Schema Include?

  • Tables: Definitions of each table, including names and columns.
  • Columns: Names, data types, constraints (e.g., NOT NULL, UNIQUE).
  • Relationships: Foreign keys that link tables together.
  • Indexes: Structures that speed up data retrieval.
  • Views: Virtual tables based on queries.
  • Stored Procedures & Functions: Reusable logic stored in the database.
  • Triggers: Automated actions based on data changes.

Schema vs. Database

  • A database is the container for all data.
  • A schema is the organizational structure within that container.
  • Some databases (like PostgreSQL or Oracle) support multiple schemas within a single database.
  • Others (like MySQL) treat each database as a single schema.