What Is a Database Schema?

Category: Databases ยท Updated 2026-11-14

A database schema is the structure that defines what a database can hold: the tables it contains, the columns in each table, the data type allowed in each column, and the rules connecting tables together. It describes the shape of the data, not the data itself, similar to a blueprint drawn before any furniture moves in.

What a schema actually defines

  • Tables: the named groups of related records, such as customers, orders or products.
  • Columns and data types: each column's name and the kind of value it accepts, such as text, integer, date or decimal.
  • Keys: a primary key that uniquely identifies each row, and foreign keys that link rows in one table to rows in another.
  • Constraints: rules such as NOT NULL, UNIQUE, or a default value, that keep bad data from being saved in the first place.

None of this is the actual data. A schema can exist, fully defined, with zero rows of real information in it.

Defining a schema with SQL

A schema is created and changed with Data Definition Language (DDL) statements such as CREATE TABLE and ALTER TABLE. A simple example for a products table:

CREATE TABLE products (
    product_id INT PRIMARY KEY AUTO_INCREMENT,
    name VARCHAR(100) NOT NULL,
    price DECIMAL(10,2) NOT NULL,
    category_id INT,
    FOREIGN KEY (category_id) REFERENCES categories(category_id)
);

This statement defines the shape of every future product row, including that a product must have a name and a price, before a single product has been added.

"Schema" means slightly different things by database

SystemWhat "schema" usually means
MySQL / MariaDBEssentially the same thing as a database; the terms are often used interchangeably
PostgreSQLA named namespace inside a single database that can hold its own set of tables, separate from other schemas in the same database
General conceptThe overall structure of tables, columns and relationships, regardless of the specific system

This distinction matters mainly when reading documentation or connection settings, since a PostgreSQL connection string can specify both a database and a schema within it.

Why a well-planned schema matters

A clear schema, planned before writing application code, prevents inconsistent data such as a price field that sometimes holds text, and it makes relationships between tables explicit rather than guessed at later. Changing a live schema once an application is in production, for example adding a column, is still possible through migrations, but it requires more care than designing it correctly from the start.

Frequently asked questions

What is a database schema in simple terms?

A database schema is the structure of a database: the tables it will have, the columns in each table, and the type of data each column accepts, laid out before any real records exist.

What is the difference between a schema and a database?

In MySQL the two terms are mostly interchangeable. In PostgreSQL, a schema is a namespace inside one database that can group its own set of tables, so a single database can contain several schemas.

What is the difference between a schema and a table?

A schema describes the entire structure, which can include many tables, while a table is one specific named group of rows and columns within that structure.

Do I need to design a schema before building an app?

It helps a great deal. Planning tables, columns and relationships first prevents inconsistent data and expensive restructuring later, though schemas can still be adjusted afterward through migrations.

How can I see the schema of my website's database?

Tools such as phpMyAdmin show a "Structure" tab for each table listing its columns and types, and dedicated tools like MySQL Workbench or pgAdmin can display or export the full schema visually.

Can a database schema change after the site is live?

Yes, through migration scripts or manual ALTER TABLE statements, though changes should be tested carefully since they can affect existing data and any application code that expects the old structure.

Related topics