schema-exploration

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Schema Exploration Skill

Schema探索技能

When to Use This Skill

何时使用该Skill

Use this skill when you need to:
  • Understand the database structure
  • Find which tables contain certain types of data
  • Discover column names and data types
  • Map relationships between tables
  • Answer questions like "What tables are available?" or "What columns does the Customer table have?"
当你需要以下操作时使用该Skill:
  • 理解数据库结构
  • 查找包含特定类型数据的表
  • 发现列名和数据类型
  • 映射表之间的关系
  • 回答诸如“有哪些可用的表?”或“Customer表有哪些列?”这类问题

Workflow

工作流程

1. List All Tables

1. 列出所有表

Use
sql_db_list_tables
tool to see all available tables in the database.
This returns the complete list of tables you can query.
使用
sql_db_list_tables
工具查看数据库中所有可用的表。
该工具会返回你可以查询的完整表列表。

2. Get Schema for Specific Tables

2. 获取特定表的Schema

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
使用
sql_db_schema
工具并指定表名,可查看以下信息:
  • 列名 - 可用的字段有哪些
  • 数据类型 - INTEGER、TEXT、DATETIME等
  • 示例数据 - 3行示例数据以帮助理解内容
  • 主键 - 行的唯一标识符
  • 外键 - 与其他表的关系

3. Map Relationships

3. 映射关系

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
确定表之间的连接方式:
  • 查找以“Id”结尾的列(例如CustomerId、ArtistId)
  • 外键关联到其他表的主键
  • 记录父子关系

4. Answer the Question

4. 回答问题

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 artists
2. Album - Music albums
3. Track - Individual songs
4. Genre - Music genres
5. MediaType - File formats (MP3, AAC, etc.)
6. Playlist - User-created playlists
7. PlaylistTrack - Tracks in playlists
8. Customer - Store customers
9. Employee - Store employees
10. Invoice - Customer purchases
11. InvoiceLine - Individual items in invoices
步骤1: 使用
sql_db_list_tables
响应:
Chinook数据库包含11个表:
1. Artist - 音乐艺术家
2. Album - 音乐专辑
3. Track - 单曲
4. Genre - 音乐流派
5. MediaType - 文件格式(MP3、AAC等)
6. Playlist - 用户创建的播放列表
7. PlaylistTrack - 播放列表中的曲目
8. Customer - 商店客户
9. Employee - 商店员工
10. Invoice - 客户订单
11. InvoiceLine - 订单中的单个商品

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

示例:“Customer表有哪些列?”

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
步骤1: 使用
sql_db_schema
工具并指定表名“Customer”
响应:
Customer表包含以下列:

- CustomerId (INTEGER) - 主键,客户唯一ID
- FirstName (NVARCHAR) - 客户名字
- LastName (NVARCHAR) - 客户姓氏
- Company (NVARCHAR) - 公司名称(可选)
- Address、City、State、Country、PostalCode - 地理位置字段
- Phone (NVARCHAR) - 电话号码
- Fax (NVARCHAR) - 传真号码
- Email (NVARCHAR) - 电子邮箱地址
- SupportRepId (INTEGER) - 关联到Employee表的外键

示例数据包含以下客户:
- 来自巴西的Luís Gonçalves
- 来自德国的Leonie Köhler
- 来自加拿大的François Tremblay

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:many
Album (ArtistId, AlbumId)
  ↓ 1:many
Track (AlbumId, TrackId)
  ↓ 1:many
InvoiceLine (TrackId, UnitPrice, Quantity)
Response:
To find revenue by artist, you'll need to:
1. Start with the Artist table
2. JOIN to Album on ArtistId
3. JOIN to Track on AlbumId
4. JOIN to InvoiceLine on TrackId
5. SUM the revenue (UnitPrice * Quantity)
6. GROUP BY artist name

This requires the query-writing skill to execute.
步骤1: 确定所需的表
  • Artist(包含艺术家名称)
  • Album(关联艺术家与曲目)
  • Track(关联专辑与销售数据)
  • InvoiceLine(包含销售数据)
  • Invoice(包含收入总额)
步骤2: 映射关系
Artist (ArtistId)
  ↓ 1:many
Album (ArtistId, AlbumId)
  ↓ 1:many
Track (AlbumId, TrackId)
  ↓ 1:many
InvoiceLine (TrackId, UnitPrice, Quantity)
响应:
要按艺术家统计收入,你需要执行以下步骤:
1. 从Artist表开始
2. 通过ArtistId关联到Album表
3. 通过AlbumId关联到Track表
4. 通过TrackId关联到InvoiceLine表
5. 计算收入总和(UnitPrice * Quantity)
6. 按艺术家名称分组

这需要使用查询编写技能来执行。

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)
对于“列出表”的问题:
  • 显示所有表名
  • 为每个表添加简短的用途描述
  • 对相关表进行分组(例如音乐目录、交易、人员)
对于“描述表”的问题:
  • 列出所有列及其数据类型
  • 说明每列包含的内容
  • 显示示例数据以提供上下文
  • 标注主键和外键
  • 说明与其他表的关系
对于“如何查询X”的问题:
  • 确定所需的表
  • 映射关联路径
  • 说明关系链
  • 建议后续步骤(使用查询编写技能)

Common Exploration Patterns

常见探索模式

Pattern 1: Find a Table

模式1:查找表

"Which table has customer information?" → Use list_tables, then describe Customer table
“哪个表包含客户信息?” → 先使用list_tables工具,再描述Customer表

Pattern 2: Understand Structure

模式2:理解结构

"What's in the Invoice table?" → Use schema tool to show columns and sample data
“What's in the Invoice table?” → 使用schema工具查看列和示例数据

Pattern 3: Map Relationships

模式3:映射关系

"How are artists connected to sales?" → Trace the foreign key chain: Artist → Album → Track → InvoiceLine → Invoice
“艺术家与销售数据如何关联?” → 跟踪外键链:Artist → Album → Track → InvoiceLine → Invoice

Tips

提示

  • Table names in Chinook are singular and capitalized (Customer, not customers)
  • Foreign keys typically have "Id" suffix and match a table name
  • Use sample data to understand what values look like
  • When unsure which table to use, list all tables first
  • Chinook数据库中的表名为单数且首字母大写(例如Customer,而非customers)
  • 外键通常以“Id”结尾,且与对应表名匹配
  • 使用示例数据了解数据值的格式
  • 不确定使用哪个表时,先列出所有表