SQL Server Management Studio 中的 GitHub Copilot(SSMS)可加快 SSMS 工作流中的工作效率,包括编写和编辑 Transact-SQL(T-SQL)。 若要充分利用 SSMS 中的 GitHub Copilot,应了解如何有效地与之协作。 与任何合作伙伴一样,当给定明确的方向和适当的上下文时,SSMS 中的 GitHub Copilot 性能最佳。 聊天窗口的最佳使用还增强了在 SSMS 中使用 GitHub Copilot 的体验质量。
聊天窗口
聊天窗口的图标和功能记录在 SQL Server Management Studio 中使用 GitHub Copilot 聊天体验(预览版),但还有其他特定于提示的注意事项。
主要是不要将聊天窗口视为结果窗口。 当向 GitHub Copilot 询问有关架构或数据的问题时,它可能会直接执行查询以在聊天窗口中返回信息。 SSMS 中的 GitHub Copilot 不会确定查询在执行之前返回的行数,如果查询返回 1,000 行,它将尝试在聊天中显示该信息。 大型结果集在聊天窗口中不容易读取,并且无法进行操作。
要求 SSMS 中的 GitHub Copilot 编写查询以返回信息通常是首选的,并与 GitHub Copilot 建立更好的交互和体验。
一致性
使用 Copilot 用户常见的挫折感是其响应不一致。 AI 响应可能不一致,因为它们是概率生成的,而不是确定性的。 这意味着,即使被问到相同的问题,模型可能会因为上下文、配置或内部随机性的细微变化而选择不同但仍然合理的一组字词或句子结构。 此外,AI 模型权衡了对提示的许多潜在解释,因此措辞或计时方面的小变化可能会导致不同的结果。 这种可变性是 AI 如此灵活和强大的一部分,但如果未以最佳方式构造提示,也可能导致不可预知的结果。
提示写入
使用 AI 固有的是编写提交提示,就像性能优化一样,它是一种艺术和科学。 无需成为提示工程师才能编写良好的提示。 但是,在使用 AI 时,需要了解一般准则。
例如,如果问 Find the hottest tables in the database,SSMS 中的 GitHub Copilot 可能不明白,在此提示的上下文中,最热的表是那些最繁忙或最活跃的表。 相反,请尝试 List the top 10 tables in the database that have the most reads。
一般提示文本写作建议包括:
| 建议 | 详细信息 |
|---|---|
| 使用自然语言 | 无需使用专用词汇,但尽量避免非正式短语、俚语和行话。 |
| 明确且具体 | 提供足够的详细信息,以便 GitHub Copilot 清楚地了解要问的内容。 |
| 提供上下文 | SSMS 中的 GitHub Copilot 具有基于查询编辑器连接的连接和数据库上下文,但可以提供额外的上下文,例如时间范围或特定数据库对象。 |
| 使用示例 | 基于以前的响应(例如 Modify the last query to order the results by CustomerID)。 |
| 定义输出格式 | GitHub Copilot 可以提供文本、表或列表格式的信息。 它为你选择,但你可以专门要求以所需的格式返回信息。 |
示例提示:
| 建议 | 避免 | 试用 |
|---|---|---|
| 使用自然语言 | Yo cook me up something cool for grabbing sales data |
Write a SQL query that selects the top 10 most recent orders from the Sales.Orders table |
| 明确且具体 | Okay, so I've got this thing where I need to maybe get some kind of report or output or whatever for yesterday's stuff but like only for users that are new but not too new, if that makes sense |
Write a query to return users who registered yesterday and have not yet made a purchase |
| 提供上下文 | List western schools with no language reqs |
List schools in the US-West geo that have a lang_req value of 0 |
| 使用示例 | Write a query to get recent customer info |
Write a query to get customer ID, name, and total number of orders for the last 10 business days ordered by total desc |
| 定义输出格式 | Give me hospital locations and size with the busiest emergency rooms |
List the hospitals with the busiest emergency rooms in table format and include city state and size |