← Module 05 · Database & SQL
05 · DATABASE & SQL · NEW TOPIC
Schema
A database schema is the blueprint that defines how database data and objects are structured.
01 · What is it?
A schema is the blueprint for a database.
It describes which objects exist, how they are organized, and what rules connect them. A schema can define tables, columns, data types, relationships, constraints, and indexes.
Simple Definition: A schema describes the shape and rules of database data.
02 · Think of it like…
Think of a schema as the floor plan for an organized building.
The building is the database. Rooms are tables, labeled spaces are columns, and doors between rooms are relationships. The floor plan tells people where things belong before anything is stored.
DATABASE→SCHEMA→TABLES→ROWS
03 · What does it do?
A schema gives the database a shared structure and set of rules. It helps software know:
What can existTables, views, functions, and other objects.
What data looks likeColumns, data types, and allowed values.
How data connectsRelationships between tables and records.
What rules applyConstraints that protect data quality.
How to find itIndexes that support efficient access.
04 · Where is it used?
Schemas are used anywhere an application needs structured, reliable data.
Product databasesUsers, orders, products, and payments.
Team-owned dataSeparate namespaces for different services or teams.
Database toolsObject browsers and query tools use schemas to organize what they show.
Application deliveryMigrations create and update schema structure across environments.
05 · Example
A migration can define a schema and then create a table inside it.
CREATE SCHEMA shop;
CREATE TABLE shop.orders (
order_id INTEGER PRIMARY KEY,
customer_id INTEGER NOT NULL,
total DECIMAL(10, 2) NOT NULL,
created_at TIMESTAMP NOT NULL
);
| Schema object | Role |
shop | The schema namespace. |
orders | A table inside that schema. |
order_id | A column with a primary-key rule. |
created_at | A column with a timestamp data type. |
06 · How it connects
Application
→
SQL migration
→
Schema
→
Tables & rules
→
Query results
The application sends SQL or uses a data-access layer; the schema gives those operations a known structure to work with.
07 · Do Not Confuse
Schema ≠ Database
A database is the larger storage system. A schema is an organized structure inside it.
Schema ≠ Table
A schema can contain many tables. A table stores one kind of structured records.
Schema ≠ SQL
SQL is the language used to define or work with data. A schema is the structure being described.
Schema ≠ Data
The schema defines the shape and rules; rows are the actual stored values.
08 · Topic Glossary
| ENGLISH TERM | 中文 | SIMPLE ENGLISH | 中文小白理解 |
| Schema | 数据库模式 / 结构 | The blueprint that defines how database data and objects are organized. | 规定数据库里的数据和对象应该怎样组织的蓝图。 |
| Database | 数据库 | A system that stores and manages application data. | 用来保存和管理应用数据的系统。 |
| Table | 表 | A structure that stores related records in rows and columns. | 用行和列保存一类相关记录的数据结构。 |
| Column | 列 / 字段 | A named type of value stored for each record. | 每条记录都可能有的某一种数据,例如金额或状态。 |
| Constraint | 约束 | A rule that limits which data is allowed. | 限制哪些数据可以被保存的规则。 |
| Relationship | 关系 | A connection between data in different tables. | 不同数据表中的数据之间建立的联系。 |
| Migration | 迁移 | A versioned change that updates database structure or data. | 按版本记录、用来更新数据库结构或数据的变更。 |
| Namespace | 命名空间 | A named area that groups objects and helps distinguish them. | 把对象分组并帮助区分它们的命名区域。 |
09 · What to Remember
A schema is the blueprint that defines the structure and rules of database objects.
Tables, columns, relationships, constraints, and indexes can all be part of that structure.
SQL migrations change the schema so application code and database structure stay aligned.
Schema→Tables→Rows