이 빠른 시작에서는 쿼리 작성 도우미를 사용하여 원시 SQL 또는 선호하는 ORM을 사용하여 효율적이고 정확하며 안전한 쿼리를 만드는 방법을 알아봅니다. 코드 우선 및 데이터 우선 개발자를 위해 설계된 이 기능을 사용하면 연결된 데이터베이스 스키마에 맞춰 프로덕션 준비 논리를 더 빠르게 생성할 수 있습니다.
시작하기
데이터베이스에 연결되어 있고 MSSQL 확장으로 활성 편집기 창이 열려 있는지 확인합니다. 이 연결을 사용하면 채팅 참가자가 @mssql 데이터베이스 환경의 컨텍스트를 이해할 수 있으므로 정확하고 컨텍스트 인식 제안을 사용할 수 있습니다. 데이터베이스 연결이 없으면 채팅 참가자는 의미 있는 응답을 제공하는 스키마 또는 데이터 컨텍스트가 없습니다.
다음 예제에서는 AdventureWorksLT2022 홈페이지에서 다운로드할 수 있는 샘플 데이터베이스를 사용합니다.
최상의 결과를 위해 사용자 고유의 환경에 맞게 테이블 및 스키마 이름을 조정합니다.
@mssql 접두사가 채팅에 포함되어 있는지 확인하세요. 예를 들어, @mssql을 입력한 후에 질문이나 프롬프트를 작성합니다. 이렇게 하면 채팅 참가자가 SQL 관련 지원을 요청하는 것을 이해할 수 있습니다.
쿼리 작성
GitHub Copilot는 Visual Studio Code 내에서 직접 지능형 쿼리 생성을 지원합니다. 기본 SELECT부터 복잡한 조인, 필터 및 집계에 이르기까지 모범 사례를 따르고 현재 스키마를 반영하는 SQL 또는 ORM 쿼리를 생성하므로 애플리케이션 논리에 집중할 수 있습니다.
다음은 채팅 참가자를 통해 요청할 수 있는 일반적인 사용 사례 및 예제입니다.
시간 기반 분석
이러한 프롬프트는 최근 판매 활동, 기간별 상위 성과자 또는 기록 평균 비교와 같은 시간에 따른 추세를 분석하는 데 도움이 됩니다. GitHub Copilot는 데이터의 최신 날짜를 기준으로 값을 계산하는 쿼리를 작성하여 현재 시스템 날짜에 따른 가정을 방지할 수 있습니다.
지난 6개월 동안 평균 이상의 판매 주문의 반환 목록
Generate a nested query to fetch orders from `SalesLT.SalesOrderHeader` where the total is above the average order amount for the last six months, relative to the most recent order date in the database (not relative to the current date).
연도별로 그룹화된 상위 3개 고객 반환
Write a query to find the top three customers by total sales in the `SalesLT.SalesOrderHeader` table, grouped by year.
지난 30일 동안 고객당 총 수익 반환
Find the total revenue for each customer in `SalesLT.Customer` who has placed orders in the last 30 days, relative to the most recent order date in `SalesLT.SalesOrderHeader` (not relative to the current date).
지난 해의 고객 및 주문 반환
Create a Sequelize query to fetch `Customers` (`SalesLT.Customers`) along with their orders (`SalesLT.SalesOrderDetail`) and total revenue, sorted by descending revenue during the last year in the database (not relative to the current date).
복잡한 관계
이러한 프롬프트를 사용하여 여러 관련 테이블에 걸쳐 있는 쿼리를 생성합니다. 고객 데이터를 주문 세부 정보와 조인하거나 수익 집계를 구축하는 경우 GitHub Copilot는 스키마 컨텍스트를 사용하여 복잡한 관계를 탐색하여 정확한 조인 및 조건을 생성하는 데 도움이 됩니다.
평균 합계를 초과하는 주문 목록을 반환합니다.
Using the actual schema of the `SalesLT.SalesOrderHeader` table, generate a nested SQL query that retrieves orders where the order total is above the average order total for the last six months. The six-month period should be calculated relative to the most recent order date in the table (not the current date).
수익별로 주문한 고객 반환
Using my current database, create a SQLAlchemy query to fetch customers along with their orders and total revenue, sorted by descending revenue.
고객당 총 수익에 대한 쿼리 생성
Using Prisma, generate a query that joins `SalesLT.Customer`, `SalesLT.SalesOrderHeader`, and `SalesLT.SalesOrderDetail` and calculates total revenue per customer.
매출별 상위 10개 고객 반환
In Entity Framework, write a LINQ query that returns the top 10 customers by sales in the past year using the `SalesLT` schema.
최근 판매를 기준으로 판매되지 않은 반품 제품
Write a TypeORM query that finds products that haven't been sold in the last six months. The six-month period should be calculated relative to the most recent order date in the table (not the current date).
총 지출에 따라 고객 검색
Write a Django ORM query that retrieves all customers who have made purchases in the last year, sorted by total spending. The "last year" period should be calculated relative to the most recent order date in the table (not the current date).
비즈니스 인사이트
이러한 프롬프트는 데이터에서 실행 가능한 인사이트를 표시하도록 설계되었습니다. 변동 위험 고객을 식별하는 것부터 판매되지 않은 제품을 찾는 것까지 GitHub Copilot는 연결된 데이터베이스에 맞게 전략적 의사 결정 및 보고를 지원하는 논리를 빌드하는 데 도움이 될 수 있습니다.
새 고객 식별
Using my current database, generate a list that shows which customers have placed their first order in the last six months, using the most recent order date in the database as the reference point.
최근 판매가 없는 제품 식별
Using my current database, generate a list that identifies products that haven't been sold in the last 12 months, using the most recent order date in the database as the reference.
최근 구매가 없는 고부가가치 고객 식별
Identify customers who have placed more than five orders but none in the last 90 days, using the most recent order date in the database as reference.
수익률에 따라 상위 5개 제품 반환
List the top five products with the highest return rate based on order returns or cancellations, calculated relative to the most recent order date.
월별 수익 추세 데이터 생성
Generate a trend of monthly revenue over the last 12 months based on `OrderDate` in `SalesLT.SalesOrderHeader`, using the most recent order date as the anchor.
감소하는 주문 빈도 보고서 만들기
Using SQLAlchemy and Pandas, create a report that identifies customers with declining order frequency over the last three quarters based on the most recent order date.
사용자 경험 공유
MSSQL 확장에 대한 GitHub Copilot를 구체화하고 개선하는 데 도움이 되도록 다음 GitHub 문제 템플릿을 사용하여 피드백을 제출합니다. GitHub Copilot 피드백
피드백을 제출할 때 다음을 포함하는 것이 좋습니다.
테스트된 시나리오 – 스키마 만들기, 쿼리 생성, 보안, 지역화와 같이 집중한 영역을 알려주세요.
잘 작동하는 기능 – 원활하거나 도움이 되거나 예상을 초과한 모든 경험을 설명합니다.
문제 또는 버그 – 문제, 불일치 또는 혼란스러운 동작을 포함합니다. 스크린샷 또는 화면 녹화는 특히 유용합니다.
개선 제안 - 유용성 향상, 적용 범위 확장 또는 GitHub Copilot의 응답 향상을 위한 아이디어를 공유합니다.