> 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/reference/sql-commands/sql-createtable/sql-createtable-referential-actions.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# CREATE TABLE：外鍵參照動作

[返回 CREATE TABLE 主頁](https://docs.postgresql.tw/19/reference/sql-commands/sql-createtable.md)。

## `NO ACTION` [#](#sql-createtable-parms-references-refact-no-action) <a href="#sql-createtable-parms-references-refact-no-action" id="sql-createtable-parms-references-refact-no-action"></a>

若刪除或更新會造成違反外鍵限制條件，就產生錯誤。若限制條件已延遲，而在檢查限制條件時仍存在任何參照的資料列，就會在那時產生此錯誤。這是預設動作。

## `RESTRICT` [#](#sql-createtable-parms-references-refact-restrict) <a href="#sql-createtable-parms-references-refact-restrict" id="sql-createtable-parms-references-refact-restrict"></a>

若要刪除或更新的資料列與參照資料表中的某個資料列相符，就產生錯誤。即使動作之後的狀態不會違反外鍵限制條件，這也會阻止該動作。特別是，它會阻止將被參照的資料列更新為不同但比較結果相等的值。（但它不會阻止將欄位更新為相同值的「無操作」更新。）

在時態外鍵中不支援此選項。

## `CASCADE` [#](#sql-createtable-parms-references-refact-cascade) <a href="#sql-createtable-parms-references-refact-cascade" id="sql-createtable-parms-references-refact-cascade"></a>

分別為：刪除參照了被刪除資料列的任何資料列，或將參照欄位的值更新為被參照欄位的新值。

在時態外鍵中不支援此選項。

## `SET NULL [ ( column_name [, ... ] ) ]` [#](#sql-createtable-parms-references-refact-set-null) <a href="#sql-createtable-parms-references-refact-set-null" id="sql-createtable-parms-references-refact-set-null"></a>

將所有參照欄位，或參照欄位中指定的子集合，設為 null。只有 `ON DELETE` 動作才能指定欄位的子集合。

在時態外鍵中不支援此選項。

## `SET DEFAULT [ ( column_name [, ... ] ) ]` [#](#sql-createtable-parms-references-refact-set-default) <a href="#sql-createtable-parms-references-refact-set-default" id="sql-createtable-parms-references-refact-set-default"></a>

將所有參照欄位，或參照欄位中指定的子集合，設為其預設值。只有 `ON DELETE` 動作才能指定欄位的子集合。（若預設值不是 null，被參照資料表中必須存在與預設值相符的資料列，否則操作會失敗。）

在時態外鍵中不支援此選項。

***

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


---

# 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/reference/sql-commands/sql-createtable/sql-createtable-referential-actions.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.
