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

# ROLLBACK

### ROLLBACK

ROLLBACK — 中止目前的交易

### 語法

```

ROLLBACK [ WORK | TRANSACTION ] [ AND [ NO ] CHAIN ]
```

### 說明

`ROLLBACK` 會回復目前的交易，並使該交易所做的 所有更新都被捨棄。

### 參數

`WORK`\
`TRANSACTION` [#](#SQL-ROLLBACK-TRANSACTION) : 可省略的關鍵字，沒有任何效果。

`AND CHAIN` [#](#SQL-ROLLBACK-CHAIN) : 如果指定了 `AND CHAIN`，系統會立即以與剛結束的交易相同的交易特性（請參閱 [SET TRANSACTION](https://docs.postgresql.tw/19/reference/sql-commands/sql-set-transaction.md)），開始一個新的（未中止的）交易。否則，不會開始新的交易。

### 注意

請使用 [`COMMIT`](https://docs.postgresql.tw/19/reference/sql-commands/sql-commit.md) 來成功地 結束一個交易。

在交易區塊之外發出 `ROLLBACK` 會產生警告， 但除此之外沒有任何效果。在交易區塊之外的 `ROLLBACK AND CHAIN` 則會產生錯誤。

### 範例

中止所有變更：

```

ROLLBACK;
```

### 相容性

`ROLLBACK` 指令符合 SQL 標準。 `ROLLBACK TRANSACTION` 這種形式則是 PostgreSQL 的擴充功能。

### 另請參閱

[BEGIN](https://docs.postgresql.tw/19/reference/sql-commands/sql-begin.md), [COMMIT](https://docs.postgresql.tw/19/reference/sql-commands/sql-commit.md), [ROLLBACK TO SAVEPOINT](https://docs.postgresql.tw/19/reference/sql-commands/sql-rollback-to.md)

***

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


---

# 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-rollback.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.
