Schema Exploration

作者 langchain-ai6a3a12bc5b3a无许可证30K 个星标收录于 2026年10月8日更新于 2026年10月8日仓库今天更新

Lists tables, describes columns and data types, identifies foreign key relationships, and maps entity relationships in a database. Use when the user asks about database schema, table structure, column types, what tables exist, ERD, foreign keys, or how entities relate.

仅含说明Data & Analytics
AI 生成的概览

探索数据库模式:列出表、说明列与数据类型,并梳理外键关系。

功能
指导智能体使用 sql_db_list_tables 和 sql_db_schema 工具检查数据库模式。它会产出带简要说明的表清单、包含数据类型与示例行的列清单,以及展示实体间主键与外键关联的关系图。它还会说明诸如按艺术家统计收入这类问题所需的连接路径,并将查询执行交给单独的查询编写技能。
适用场景
当用户询问有哪些表、某张表有哪些列或数据类型、实体之间如何关联,或需要 ERD 与外键概览时使用。它适合在编写查询之前先了解模式,而不是执行查询本身。
运行要求
需要 sql_db_list_tables 和 sql_db_schema 工具以及对数据库的访问权限。不附带脚本,仅为说明性指令。

Schema Exploration Skill

Workflow

1. List All Tables

Use sql_db_list_tables tool to see all available tables in the database.

This returns the complete list of tables you can query.

2. Get Schema for Specific Tables

Use sql_db_schema tool with table names to examine:

  • Column names - What fields are available
  • Data types - INTEGER, TEXT, DATETIME, etc.
  • Sample data - 3 example rows to understand content
  • Primary keys - Unique identifiers for rows
  • Foreign keys - Relationships to other tables

3. Map Relationships

Identify how tables connect:

  • Look for columns ending in "Id" (e.g., CustomerId, ArtistId)
  • Foreign keys link to primary keys in other tables
  • Document parent-child relationships

4. Answer the Question

Provide clear information about:

  • Available tables and their purpose
  • Column names and what they contain
  • How tables relate to each other
  • Sample data to illustrate content

Example: "What tables are available?"

Step 1: Use sql_db_list_tables

Response:

The Chinook database has 11 tables:1. Artist - Music artists2. Album - Music albums3. Track - Individual songs4. Genre - Music genres5. MediaType - File formats (MP3, AAC, etc.)6. Playlist - User-created playlists7. PlaylistTrack - Tracks in playlists8. Customer - Store customers9. Employee - Store employees10. Invoice - Customer purchases11. InvoiceLine - Individual items in invoices

Example: "What columns does the Customer table have?"

Step 1: Use sql_db_schema with table name "Customer"

Response:

The Customer table has these columns:
- CustomerId (INTEGER) - Primary key, unique customer ID- FirstName (NVARCHAR) - Customer's first name- LastName (NVARCHAR) - Customer's last name- Company (NVARCHAR) - Company name (optional)- Address, City, State, Country, PostalCode - Location fields- Phone (NVARCHAR) - Phone number- Fax (NVARCHAR) - Fax number- Email (NVARCHAR) - Email address- SupportRepId (INTEGER) - Foreign key to Employee table
Sample data shows customers like:- Luís Gonçalves from Brazil- Leonie Köhler from Germany- François Tremblay from Canada

Example: "How do I find revenue by artist?"

Step 1: Identify tables needed

  • Artist (has artist names)
  • Album (links artists to tracks)
  • Track (links albums to sales)
  • InvoiceLine (has sales data)
  • Invoice (has revenue totals)

Step 2: Map relationships

Artist (ArtistId)  ↓ 1:manyAlbum (ArtistId, AlbumId)  ↓ 1:manyTrack (AlbumId, TrackId)  ↓ 1:manyInvoiceLine (TrackId, UnitPrice, Quantity)

Response:

To find revenue by artist, you'll need to:1. Start with the Artist table2. JOIN to Album on ArtistId3. JOIN to Track on AlbumId4. JOIN to InvoiceLine on TrackId5. SUM the revenue (UnitPrice * Quantity)6. GROUP BY artist name
This requires the query-writing skill to execute.

Quality Guidelines

For "list tables" questions:

  • Show all table names
  • Add brief descriptions of what each contains
  • Group related tables (e.g., music catalog, transactions, people)

For "describe table" questions:

  • List all columns with data types
  • Explain what each column contains
  • Show sample data for context
  • Note primary and foreign keys
  • Explain relationships to other tables

For "how do I query X" questions:

  • Identify required tables
  • Map the JOIN path
  • Explain the relationship chain
  • Suggest next steps (use query-writing skill)

来源与署名

来源:langchain-ai/deepagents位于examples/text-to-sql-agent/skills/schema-exploration提交6a3a12b

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架