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

# 2.1. 簡介 \#

### 2.1. 簡介 [#](#tutorial-sql-intro) <a href="#tutorial-sql-intro" id="tutorial-sql-intro"></a>

本章概要說明如何使用 SQL 執行簡單的操作。本教學只是入門介紹，絕非完整的 SQL 教學。坊間已有許多關於 SQL 的書籍，包括 [\[melt93\]](https://docs.postgresql.tw/19/bibliography.md#MELT93) 與 [\[date97\]](https://docs.postgresql.tw/19/bibliography.md#DATE97)。請注意，PostgreSQL 的部分語言功能是標準的延伸。

在接下來的範例中，我們假設你已如上一章所述建立名為 `mydb` 的資料庫，並且能夠啟動 psql。

本手冊中的範例也可以在 PostgreSQL 原始碼發行版本的 `src/tutorial/` 目錄中找到。（PostgreSQL 的二進位發行版本可能不提供這些檔案。）要使用這些檔案，請先切換到該目錄並執行 make：

```

$ cd .../src/tutorial
$ make
```

這會建立腳本，並編譯包含使用者自訂函式與型別的 C 檔案。接著，依下列方式開始教學：

```

$ psql -s mydb

...

mydb=> \i basics.sql
```

`\i` 指令會從指定的檔案讀入指令。`psql` 的 `-s` 選項會讓你進入單步模式，在每個陳述式送往伺服器之前暫停。本節使用的指令都在 `basics.sql` 檔案中。

***

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


---

# 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/tutorial/tutorial-sql/tutorial-sql-intro.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.
