> For the complete documentation index, see [llms.txt](https://docs.maiagent.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.maiagent.ai/maiagent-user-guide/maiagent-user-guide-ja/agent-builder/database.md).

# データベース

<figure><img src="/files/1cHlKZv3bewha5xUEGWD" alt="データベースの概念"><figcaption><p>Text to SQL：自然言語 → SQL クエリ → 平易な回答</p></figcaption></figure>

## これは何ですか？ <a href="#what-is-this" id="what-is-this"></a>

データベースを使うと、Agent が自然言語で構造化データを照会できるようになります。利用者が「先月、ノートパソコンは何台売れましたか？」と尋ねると、Agent はその文章を自動的に SQL クエリに変換し、データベースから答えを取得して平易な言葉で回答します。

この機能の技術的な名称は **Text to SQL** です。

## どのようなときに使いますか？ <a href="#when-do-you-need-it" id="when-do-you-need-it"></a>

次のようなシーンが該当する場合です。

* **データ照会**：注文ステータス、在庫数量、売上金額
* **統計分析**：「今四半期の業績は前四半期と比べてどれくらい伸びましたか？」
* **リアルタイムの状況**：「現在、未処理の作業オーダーは何件ありますか？」

これらの質問の答えは構造化されたテーブルの中に保存されており、ドキュメントの中にあるわけではありません。そのため、ナレッジベースではなくデータベースが必要になります。

## どのようなデータベースに対応していますか？ <a href="#supported-databases" id="supported-databases"></a>

| 種類                    | 説明                                                          |
| --------------------- | ----------------------------------------------------------- |
| **MaiAgent 内蔵データベース** | プラットフォームに標準搭載されているデータベース。CSV を直接アップロードしたり、手動でテーブルを作成したりできます |
| **外部データベース**          | お使いの PostgreSQL、MySQL、SQL Server、Oracle に接続します              |

## 安全ですか？ <a href="#is-it-secure" id="is-it-secure"></a>

Agent は**読み取り専用クエリ**（SELECT）のみを実行し、お客様のデータを変更したり削除したりすることはありません。また、Agent がアクセスできるテーブルやカラムを制限することもできます。

> **詳細説明**：Text to SQL の精度は、テーブル構造の分かりやすさによって左右されます。テーブルやカラムに日本語の説明を付け、各カラムが何を表しているのかを Agent が理解しやすくすることをおすすめします。

## 何をする必要がありますか？ <a href="#what-do-i-need-to-do" id="what-do-i-need-to-do"></a>

1. **データベース接続の作成** — データベースの種類を選択し、接続情報を設定します
2. **アクセス可能なテーブルの設定** — Agent が照会できるテーブルを選択します
3. **カラムの説明の追加** — カラムに説明を付けて、照会の精度を高めます
4. **クエリのテスト** — 自然言語で、Agent が正しく照会できるかをテストします
5. **Agent への接続** — ツールの形で Agent に連携します

## さらに詳しく <a href="#further-reading" id="further-reading"></a>

* [Text to SQL 機能](/maiagent-user-guide/maiagent-user-guide-ja/database/text2sql.md)
* [MaiAgent ナレッジベースを使った Text to SQL](/maiagent-user-guide/maiagent-user-guide-ja/database/text-to-sql-maiagent.md)
* [Supabase を使った Text to SQL](/maiagent-user-guide/maiagent-user-guide-ja/tools/text-to-sql-supabase.md)


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.maiagent.ai/maiagent-user-guide/maiagent-user-guide-ja/agent-builder/database.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
