Skip to content

Normalization

一句话解释

Normalization 是处理的 structuring 表到 minimize 数据 duplication and avoid 更新 anomalies.

用大白话说

Normalization is the process of organizing your tables to reduce redundant data and avoid "anomalies" — problems that arise when you insert, update, or delete duplicated data.

There are several "normal 表单" (1NF, 2NF, 3NF, BCNF, etc.), each stricter than the last. In practice, 3NF is the most common target:

  • 1NF: Each column holds a single value (no lists in a cell).
  • 2NF: 1NF plus no partial dependency on a composite key.
  • 3NF: 2NF plus no transitive dependency (non-key columns depend only on the key).

For example, instead of storing a user's city and country in every order row, you normalize by creating a 位置 table and referencing it — the city and country are stored once.

The trade-off: normalized data avoids redundancy but may require more joins to query. Sometimes you deliberately denormalize for read performance.

示例

sql
-- Before normalization: redundant data
CREATE TABLE orders_bad (
  id INTEGER, user_name TEXT, user_city TEXT, total NUMERIC
);

-- After normalization: data stored once
CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT, city_id INTEGER);
CREATE TABLE cities (id SERIAL PRIMARY KEY, name TEXT);
CREATE TABLE orders (id SERIAL PRIMARY KEY, user_id INTEGER, total NUMERIC);

Normalization moves 用户 and city 数据到 separate 表, referenced 通过 foreign 键.

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表