> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/19/the-sql-language/ddl.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# 第 5 章 資料定義

### 第 5 章 資料定義

**目錄**

* [5.1. 資料表基礎](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-basics.md)
* [5.2. 預設值](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-default.md)
* [5.3. 識別欄位](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-identity-columns.md)
* [5.4. 產生欄位](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-generated-columns.md)
* [5.5. 限制條件](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-constraints.md)
  * [5.5.1. 檢查限制條件](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-constraints.md#ddl-constraints-check-constraints)
  * [5.5.2. 非空值限制條件](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-constraints.md#ddl-constraints-not-null)
  * [5.5.3. 唯一限制條件](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-constraints.md#ddl-constraints-unique-constraints)
  * [5.5.4. 主鍵](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-constraints.md#ddl-constraints-primary-keys)
  * [5.5.5. 外鍵](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-constraints.md#ddl-constraints-fk)
  * [5.5.6. 排除限制條件](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-constraints.md#ddl-constraints-exclusion)
* [5.6. 系統欄位](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-system-columns.md)
* [5.7. 修改資料表](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-alter.md)
  * [5.7.1. 新增欄位](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-alter.md#ddl-alter-adding-a-column)
  * [5.7.2. 移除欄位](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-alter.md#ddl-alter-removing-a-column)
  * [5.7.3. 新增限制條件](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-alter.md#ddl-alter-adding-a-constraint)
  * [5.7.4. 移除限制條件](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-alter.md#ddl-alter-removing-a-constraint)
  * [5.7.5. 變更欄位的預設值](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-alter.md#ddl-alter-column-default)
  * [5.7.6. 變更欄位的資料型別](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-alter.md#ddl-alter-column-type)
  * [5.7.7. 重新命名欄位](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-alter.md#ddl-alter-renaming-column)
  * [5.7.8. 重新命名資料表](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-alter.md#ddl-alter-renaming-table)
* [5.8. 權限](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-priv.md)
* [5.9. 資料列安全政策](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-rowsecurity.md)
* [5.10. 綱要](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-schemas.md)
  * [5.10.1. 建立綱要](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-schemas.md#ddl-schemas-create)
  * [5.10.2. public 綱要](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-schemas.md#ddl-schemas-public)
  * [5.10.3. 綱要搜尋路徑](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-schemas.md#ddl-schemas-path)
  * [5.10.4. 綱要與權限](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-schemas.md#ddl-schemas-priv)
  * [5.10.5. 系統目錄綱要](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-schemas.md#ddl-schemas-catalog)
  * [5.10.6. 使用模式](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-schemas.md#ddl-schemas-patterns)
  * [5.10.7. 可攜性](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-schemas.md#ddl-schemas-portability)
* [5.11. 繼承](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-inherit.md)
  * [5.11.1. 注意事項](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-inherit.md#ddl-inherit-caveats)
* [5.12. 資料表分割](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-partitioning.md)
  * [5.12.1. 概觀](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-partitioning.md#ddl-partitioning-overview)
  * [5.12.2. 宣告式分割](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-partitioning.md#ddl-partitioning-declarative)
  * [5.12.3. 使用繼承進行分割](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-partitioning.md#ddl-partitioning-using-inheritance)
  * [5.12.4. 分割區修剪](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-partitioning.md#ddl-partition-pruning)
  * [5.12.5. 分割與限制條件排除](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-partitioning.md#ddl-partitioning-constraint-exclusion)
  * [5.12.6. 宣告式分割的最佳實務](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-partitioning.md#ddl-partitioning-declarative-best-practices)
* [5.13. 外部資料](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-foreign-data.md)
* [5.14. 其他資料庫物件](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-others.md)
* [5.15. 相依性追蹤](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-depend.md)

本章說明如何建立用來存放資料的資料庫結構。在關聯式資料庫中，原始資料存放在資料表裡，因此本章大部分的篇幅都用來說明資料表要如何建立與修改，以及有哪些功能可以用來控制資料表中所存放的資料。接著，我們會討論如何將資料表整理到綱要之中，以及如何為資料表指派權限。最後，我們會簡要地介紹其他會影響資料儲存的功能，例如繼承、資料表分割、檢視表、函式與觸發程序。

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/ddl.html)（原文版本：18.6；核對日期：2026-09-15）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.postgresql.tw/19/the-sql-language/ddl.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
