在這個快速入門中,你會學習商業邏輯說明器如何幫助開發者理解並操作以 SQL、ORM(Object-Relational 映射)框架或直接在資料庫中實作的複雜應用邏輯。 助理會分析 SQL 程式代碼、ORM 模型或現有的資料庫架構,以說明基礎商務規則並提供可採取動作的檔。
開始
請確定您已連線到資料庫,並使用 MSSQL 擴充功能開啟使用中的編輯器視窗。 此連線可讓 @mssql 聊天參與者瞭解您的資料庫環境內容,提供精確且切合內容的建議。 如果沒有資料庫連線,聊天參與者就不會有架構或數據內容來提供有意義的回應。
下列範例使用 AdventureWorksLT2022 範例資料庫,您可以從 Microsoft SQL Server 範例和社群專案 首頁下載。
為了獲得最佳結果,請調整數據表和架構名稱以符合您自己的環境。
請確保聊天中包含@mssql前綴。 例如,輸入 @mssql ,後面接著您的問題或提示。 這可確保聊天參與者瞭解您要求與 SQL 相關的協助。
使用 GitHub Copilot 瞭解商業規則
GitHub Copilot 可協助您了解並說明內嵌在資料庫程式代碼、ORM 模型和應用程式查詢中的商務規則。 從預存程式到 LINQ 查詢和 Sequelize 運算式,GitHub Copilot 提供自然語言深入解析,讓複雜的邏輯更容易存取。
以下是您可以透過聊天參與者詢問的常見使用案例和範例:
說明 T-SQL 邏輯
使用 GitHub Copilot 來理解並解釋 Transact-SQL(T-SQL)邏輯,從儲存過程到內嵌條件語句。 無論您是檢閱折扣規則、程式邏輯或優化條件,GitHub Copilot 都可以分析和記錄 T-SQL 中實作的商務規則。
解釋一個儲存程序
Explain what the `SalesLT.uspGetCustomerOrderHistory` stored procedure does and suggest ways to optimize it.
偵錯預存程序
Debug the `SalesLT.uspGetTopSellingProducts` stored procedure and suggest improvements.
用程式碼片段解釋商業邏輯
Analyze the following SQL code snippet from my current database. Document the business rules implemented in this discount application process, including conditions for eligibility, discount rate adjustments, and any limits imposed on the discount amount. Also, provide actionable insights or suggestions to improve clarity or performance if necessary.
DECLARE @OrderTotal AS DECIMAL (10, 2) = 1500.00;
DECLARE @DiscountCode AS NVARCHAR (20) = 'DISCOUNT10';
DECLARE @DiscountPct AS DECIMAL (5, 2) = CASE WHEN @OrderTotal > 1000.00 THEN 5.0 ELSE 0.0 END;
IF @DiscountCode = 'DISCOUNT10'
BEGIN
SET @DiscountPct = CASE WHEN @DiscountPct < 10.0 THEN 10.0 ELSE @DiscountPct END;
END
DECLARE @DiscountAmount AS DECIMAL (10, 2) = (@OrderTotal * @DiscountPct / 100.0);
IF @DiscountAmount > 200.00
BEGIN
SET @DiscountAmount = 200.00;
END
SELECT @OrderTotal AS OrderTotal,
@DiscountPct AS DiscountPercentage,
@DiscountAmount AS DiscountAmount;
說明 ORM 邏輯
解釋一個 SQLAlchemy 查詢
Explain what the following SQLAlchemy query does:
from sqlalchemy import func
top_customers = (
session.query(SalesOrderHeader.CustomerID, func.count().label("OrderCount"))
.group_by(SalesOrderHeader.CustomerID)
.order_by(func.count().desc())
.limit(10)
)
解釋一個實體框架的 LINQ 查詢
What does this Entity Framework LINQ query do? Describe how it groups customers by tier based on their total purchases.
var customerTiers = context.SalesOrderHeaders
.GroupBy(o => o.CustomerID)
.Select(g => new {
CustomerID = g.Key,
TotalSpent = g.Sum(o => o.TotalDue),
Tier = g.Sum(o => o.TotalDue) >= 10000 ? "Gold" :
g.Sum(o => o.TotalDue) >= 5000 ? "Silver" : "Bronze"
});
解釋 Prisma 查詢中的商業邏輯
Analyze the logic of this Prisma query and explain how it determines which products are considered "low inventory".
const lowInventoryProducts = await prisma.product.findMany({
where: {
SafetyStockLevel: {
lt: 50
}
},
select: {
ProductID: true,
Name: true,
SafetyStockLevel: true
}
});
解釋並評論 Sequelize 的問題
Review and explain what this Sequelize query does. Add inline comments to clarify how it calculates total revenue per customer and filters for customers with significant spending:
const results = await SalesOrderHeader.findAll({
attributes: ['CustomerID', [sequelize.fn('SUM', sequelize.col('TotalDue')), 'TotalSpent']],
group: ['CustomerID'],
having: sequelize.literal('SUM(TotalDue) > 5000')
});
生成一個針對產品清單的 SQLAlchemy 查詢
Using SQLAlchemy, generate a query to list products that have never been ordered and ask GitHub Copilot to explain the join logic and filtering behavior.
使用 Prisma 查詢取得客戶資訊
In Prisma, write a query that retrieves customers who placed an order in the last 30 days. Explain what the following Prisma query does. Add inline comments to clarify how the date filtering works and how recent orders are determined:
透過查詢瞭解商務意圖
GitHub Copilot 可協助開發人員了解查詢的運作方式,以及查詢存在的原因。 此說明涵蓋了資料篩選、分組與聚合背後的實際用途。 這些說明在上線期間特別有用,可讓開發人員掌握內嵌在SQL和 ORM 程式代碼中的報表、邏輯閘道或系統計量背後的目標。
在 T-SQL 查詢中描述業務目標
Describe the business goal of the following SQL query. What insight is it trying to surface?
SELECT TOP 10 CustomerID,
COUNT(*) AS OrderCount
FROM SalesLT.SalesOrderHeader
GROUP BY CustomerID
ORDER BY OrderCount DESC;
總結 T-SQL 查詢的意圖
Summarize what this query is intended to achieve from a business perspective.
SELECT ProductID,
SUM(LineTotal) AS TotalSales
FROM SalesLT.SalesOrderDetail
GROUP BY ProductID
HAVING SUM(LineTotal) > 10000;
描述儲存程序中的商業邏輯
Analyze the `SalesLT.uspGetCustomerOrderHistory` stored procedure and describe the business logic it implements.
解釋實體框架 LINQ 查詢中的商業邏輯
Explain this Entity Framework LINQ query and describe what business logic it implements:
var highValueCustomers = context.SalesOrderHeaders
.Where(o => o.TotalDue > 1000)
.GroupBy(o => o.CustomerID)
.Select(g => new { CustomerID = g.Key, OrderCount = g.Count() })
.OrderByDescending(x => x.OrderCount)
.Take(10)
.ToList();
在 Sequelize 查詢中解釋商業假設
Using Sequelize, explain what this query does and describe any business assumptions it makes:
const customerRevenue = await SalesOrderHeader.findAll({
attributes: ['CustomerID', [sequelize.fn('SUM', sequelize.col('TotalDue')), 'TotalSpent']],
group: ['CustomerID'],
having: sequelize.literal('SUM(TotalDue) > 5000')
});
分享您的體驗
若要協助我們精簡及改善 MSSQL 延伸模組的 GitHub Copilot,請使用下列 GitHub 問題範本來提交您的意見反應: GitHub Copilot 意見反應
提交意見反應時,請考慮包括:
測試的案例 – 讓我們知道您專注於哪些領域,例如架構建立、查詢產生、安全性、當地語系化。
表現良好之處 – 描述任何感覺順暢、有幫助或超乎您期望的體驗。
問題或錯誤 – 包含任何問題、不一致或混淆的行為。 螢幕快照或螢幕錄製特別有用。
改進建議 – 分享改善可用性、擴大涵蓋範圍或增強 GitHub Copilot 回應的想法。