Skip to content

Commit 3bb1d4e

Browse files
authored
pull base content,head:MicrosoftDocs:main,into:wwlpublishsync
2 parents 91b46c0 + 8f8fa1e commit 3bb1d4e

18 files changed

+533
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.challenge-github-copilot-with-sql.introduction-github-copilot-codespaces
3+
title: Introduction to GitHub Copilot in GitHub Codespaces
4+
metadata:
5+
title: Introduction to GitHub Copilot in GitHub Codespaces
6+
description: Learn how to use GitHub Copilot in GitHub Codespaces to enhance your coding experience.
7+
ms.date: 06/25/2025
8+
author: Orin-Thomas
9+
ms.author: orthomas
10+
ms.topic: unit
11+
durationInMinutes: 7
12+
content: |
13+
[!include[](includes/1-introduction-github-copilot-codespaces.md)]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.challenge-github-copilot-with-sql.work-with-sql-using-github-copilot
3+
title: Work with SQL using GitHub Copilot
4+
metadata:
5+
title: Work With SQL Using GitHub Copilot
6+
description: Learn how to leverage GitHub Copilot to write and optimize SQL queries more efficiently.
7+
ms.date: 06/25/2025
8+
author: Orin-Thomas
9+
ms.author: orthomas
10+
ms.topic: unit
11+
durationInMinutes: 11
12+
content: |
13+
[!include[](includes/2-work-with-sql-using-github-copilot.md)]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.challenge-github-copilot-with-sql.github-skills-exercise
3+
title: Hands-on exercise - Challenging GitHub Copilot with SQL
4+
metadata:
5+
title: Hands-on exercise - Challenging GitHub Copilot with SQL
6+
description: Learn how to apply advanced GitHub Copilot features to interact with an application that uses complex SQL queries.
7+
ms.date: 06/25/2025
8+
author: Orin-Thomas
9+
ms.author: orthomas
10+
ms.topic: unit
11+
durationInMinutes: 3
12+
content: |
13+
[!include[](includes/3-github-skills-exercise.md)]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.challenge-github-copilot-with-sql.knowledge-check
3+
title: Knowledge check
4+
metadata:
5+
title: Knowledge Check
6+
description: Check your knowledge.
7+
ms.date: 06/25/2025
8+
author: Orin-Thomas
9+
ms.author: orthomas
10+
ms.topic: unit
11+
durationInMinutes: 3
12+
content: Choose the best response for each question.
13+
quiz:
14+
questions:
15+
- content: "How can GitHub Copilot assist in optimizing SQL queries within a GitHub Codespace environment?"
16+
choices:
17+
- content: "By providing general coding tips and tricks."
18+
isCorrect: false
19+
explanation: "General coding tips don't address SQL query optimization."
20+
- content: "By suggesting specific optimizations for slow or inefficient queries."
21+
isCorrect: true
22+
explanation: "GitHub Copilot can analyze SQL queries and suggest optimizations such as removing unnecessary JOINs, optimizing SELECT DISTINCT, or refactoring subqueries."
23+
- content: "By automatically rewriting all SQL queries without user input."
24+
isCorrect: false
25+
explanation: "GitHub Copilot requires user input to provide specific suggestions and doesn't automatically rewrite all queries."
26+
- content: "What is the role of GitHub Copilot in generating SQL-based tests or assertions?"
27+
choices:
28+
- content: "It can suggest appropriate testing frameworks based on the project type."
29+
isCorrect: true
30+
explanation: "GitHub Copilot can help generate SQL-based tests or assertions to verify query results or database state and suggest appropriate testing frameworks based on the project type."
31+
- content: "It can execute SQL tests automatically without user intervention."
32+
isCorrect: false
33+
explanation: "GitHub Copilot assists in generating tests but doesn't execute them automatically."
34+
- content: "It can only generate unit tests for non-SQL code."
35+
isCorrect: false
36+
explanation: "GitHub Copilot can generate tests for SQL code as well as other types of code."
37+
- content: "How can GitHub Copilot enhance the understanding of complex SQL queries?"
38+
choices:
39+
- content: "By providing detailed documentation for the entire codebase."
40+
isCorrect: false
41+
explanation: "While GitHub Copilot can generate documentation, the specific enhancement for understanding SQL queries comes from its ability to explain to them."
42+
- content: "By explaining the logic and structure of complex SQL queries."
43+
isCorrect: true
44+
explanation: "GitHub Copilot can explain complex SQL queries to help users understand their logic and structure."
45+
- content: "By rewriting SQL queries to make them simpler."
46+
isCorrect: false
47+
explanation: "Rewriting queries is related to optimization and refactoring, but doesn't increase understanding of query functionality."
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.challenge-github-copilot-with-sql.summary
3+
title: Summary
4+
metadata:
5+
title: Summary
6+
description: Summary of the module.
7+
ms.date: 06/25/2025
8+
author: Orin-Thomas
9+
ms.author: orthomas
10+
ms.topic: unit
11+
durationInMinutes: 1
12+
content: |
13+
[!include[](includes/5-summary.md)]
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
GitHub Copilot is an AI pair programmer that helps you write code faster and with less effort. Copilot works alongside you directly in your code editor, seamlessly integrating AI into your workflow. It provides intelligent code suggestions and completions based on the context of your code, helping you write code more efficiently and accurately.
2+
3+
General support features:
4+
5+
- Language Support: Supports multiple programming languages and frameworks, adapting to the code you're working on.
6+
- IDE Integration: Works directly in your code editor, providing suggestions and completions as you write code. Is available within the GitHub Codespaces environment.
7+
8+
GitHub Copilot's autocomplete features:
9+
10+
- Code line completions and suggestions are based on the context of your code.
11+
- Suggestions can be single lines of code, entire functions, or even entire classes.
12+
13+
Copilot suggestions can help you write code faster and with fewer errors, improving your productivity and efficiency.
14+
15+
GitHub Copilot Chat's AI assistance features include:
16+
17+
- Chat Interface: Provides a chat interface for interacting with GitHub Copilot, asking and receiving answers to coding-related questions.
18+
- Code Explanation: Provides explanations for selected code snippets, helping you understand syntax, programming concepts, test cases, debugging, and more, without requiring you to navigate documentation or search online forums.
19+
- Documentation Generation: Generates explanations or documentation for selected code or entire workspaces, helping you understand and document your codebase.
20+
- Test Case Generation: Helps in generating test cases for your code, saving time, and improving code quality.
21+
- Code fixes: Provides suggestions for refactoring code and fixing common issues, improving code quality and maintainability.
22+
23+
By using AI to assist with coding tasks, GitHub Copilot can help you focus on higher-level design and problem-solving, rather than getting bogged down in syntax and implementation details.
24+
25+
## Understand GitHub Codespaces
26+
27+
GitHub Codespaces provides a cloud hosted development environment, ready to use and accessible from any computer with an internet connection and standards compliant web browser. You use GitHub Codespaces within your browser and when a codespace is loaded, you interact with it as you would any traditional IDE. GitHub Codespaces provides you with an environment that includes all the essential languages, tools, and utilities you need to code effectively.
28+
29+
![A screenshot of the GitHub Codespace interface, showing the explorer, a readme file, and the Ask Copilot pane.](../media/codespace-interface.svg)
30+
31+
You can also use the terminal pane within a GitHub Codespace to run commands, such as python scripts.
32+
33+
![A screenshot showing a python script being called from a GitHub codespace.](../media/run-python-terminal.svg)
34+
35+
## Create a GitHub Codespace
36+
37+
To begin developing using GitHub Codespaces, you can create a codespace from a template or from any branch or commit in a GitHub repository. When you create a codespace from a template, you can start from a blank template or choose a template suitable for the work you're doing.
38+
39+
For example, you can:
40+
41+
- Create a codespace from your GitHub repository.
42+
- Push code from the codespace to your GitHub repository.
43+
- Use VS Code to develop code within the codespace.
44+
- Customize the codespace with custom images.
45+
46+
To open a codespace from your GitHub account, start at the landing page of your repository, choose the Code button, and then choose Create codespace on the repository on the Codespaces tab.
47+
48+
![A screenshot showing how to open a GitHub Codespace from a GitHub repository.](../media/open-codespace-repository.svg)
49+
50+
## Customize GitHub Codespaces
51+
52+
You can customize your project for GitHub Codespaces by committing configuration files to your repository (also known as configuration-as-code), which creates a repeatable codespace configuration for all users of your project. Each codespace you create is hosted by GitHub in a Docker container that runs on a virtual machine. You can choose the type of virtual machine you want to use depending on the resources you need.
53+
54+
You can configure the development container for a repository so that any codespace created for that repository gives you a tailored development environment, complete with all the tools and runtimes you need to work on a specific project. A development container file is a JSON file that lets you customize the default container image that runs your codespace. You can use this JSON file to configure VS Code settings, run custom code, manage network traffic port forwarding, and configure other settings.
55+
56+
## GitHub Copilot in GitHub Codespaces
57+
58+
One of the tools you can use within a GitHub Codespace is GitHub Copilot. You can verify that GitHub Copilot and Copilot Chat are available in your GitHub Codespaces environment by checking the Extensions tab and searching for GitHub Copilot and choosing the Install option if GitHub Copilot isn't already present.
59+
60+
![A screenshot of the Extensions pane showing the GitHub Copilot extension.](../media/install-copilot.svg)
61+
62+
You can use the GitHub Copilot icon to open the Copilot Chat panel. You can use the chat panel to interact with code and other artifacts within the GitHub Codespace interface.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
GitHub Copilot can be used to interact with all types of code, this includes interacting with popular programing languages and providing you with the option of writing, debugging, and optimizing SQL code.
2+
3+
GitHub Copilot can perform the following tasks related to SQL code:
4+
5+
- Query Explanation: Use Copilot to explain complex SQL queries to better understand their logic and structure.
6+
- Query Optimization: Ask Copilot for suggestions to optimize slow or inefficient queries, such as removing unnecessary JOINs, optimizing SELECT DISTINCT, or refactoring subqueries.
7+
- Query Refactoring: Request Copilot to rewrite queries for better readability or maintainability, e.g., replacing CROSS JOINs or simplifying nested queries.
8+
- Generating Queries: Have Copilot generate new SQL queries based on your data requirements, such as SELECT, INSERT, UPDATE, or DELETE statements.
9+
- Data Validation: Use Copilot to help write SQL queries that validate data integrity or check for specific conditions in your database.
10+
- Schema Exploration: Ask Copilot to help you write queries that explore or document your database schema (e.g., listing tables, columns, or relationships).
11+
- Test Generation: Request Copilot to generate SQL-based tests or assertions to verify query results or database state.
12+
- Error Debugging: Ask Copilot to help debug SQL errors or suggest fixes for common issues (e.g., syntax errors, missing indexes).
13+
- Prompt Creation: Have Copilot generate prompts or templates for creating high-performing queries from scratch.
14+
15+
GitHub Copilot provides better outcomes when your prompts are more specific. If you provide general prompts, you're likely to receive general answers. If you provide more detail in your prompts and ask more detailed questions, you're more likely to get detailed answers.
16+
17+
For example, you could use GitHub Copilot to provide you with the SQL code to create a table that included columns for first name, last name, date of birth, favorite movie, and pet name by issuing the following prompt:
18+
19+
_@workspace Please provide me with the SQL code to create a table that included columns for first name, last name, date of birth, favorite movie and pet name_
20+
21+
![A screenshot a GitHub Copilot prompt related to the creation of a table in SQL.](../media/create-table.svg)
22+
23+
## Understand an application that includes SQL
24+
25+
For example, if you opened a codespace were presented with an application that included SQL code, you could query GitHub Copilot with the following prompt to understand more about the project in the following manner:
26+
27+
_@workspace Please briefly explain the structure of this project.
28+
What should I do to run it?_
29+
30+
![A screenshot showing GitHub Copilot's response to a query about project structure.](../media/project-structure.svg)
31+
32+
## Understand SQL code
33+
34+
You can use the /explain prompt to understand specific code. For example, a project might contain a file named complex.sql, which contains the query that is being executed in the application. To understand the contents of complex.sql, you can select it within the Explorer pane of GitHub Codespaces and then use the /explain prompt in the chat.
35+
36+
![A screenshot of a computer screen AI-generated content may be incorrect.](../media/examine-sql.svg)
37+
38+
Rather than selecting the whole file, you're able to select sections of the code and ask GitHub Copilot to provide a detail about those sections.
39+
40+
## Optimize and refactor SQL queries
41+
42+
Sometimes you're presented with queries that are slow or inefficient because there are unnecessary JOINS, tables queried don't have indexes or contain redundant nested subqueries. Using GitHub Copilot, you can select a query and prompt for any optimizations that may improve performance.
43+
44+
Similarly, you can request Copilot to rewrite queries for better readability or maintainability, asking Copilot to provide comments to explain functionality for future developers who may need to review the code.
45+
46+
An example prompt might be:
47+
48+
_"Add detailed comments to the complex.sql file explaining the purpose and functionality of each CTE, SQL clause, and calculation. Make sure to describe what each section of the query does, including how the year is extracted, how the rolling average is computed, the logic behind the performance ratio, and the meaning of each CASE statement. The comments should make it easy for someone unfamiliar with the file to understand the logic and intent of the entire query."_
49+
50+
## Validate integrity of data
51+
52+
Use Copilot to help write SQL queries that validate data integrity or check for specific conditions in your database. For example, you could prompt GitHub Copilot to perform one of the four types of integrity checks:
53+
54+
- Uniqueness / duplicate checks
55+
- Referential integrity (foreign key violations)
56+
- Domain integrity (values within expected ranges)
57+
- Business rule checks (custom logic violations)
58+
59+
An example query might be:
60+
61+
_"Write a SQL query that checks for orphaned foreign keys between Orders and Customers tables."_
62+
63+
## Database schema documentation
64+
65+
You can ask GitHub Copilot to help you write queries that explore or document your database schema. By giving GitHub Copilot the context of the database you're working with, you'll be able to determine whether the code that interacts with that database can be optimized. While GitHub Copilot doesn't deeply analyze the execution plans of queries, but understanding the context of the SQL database you're interacting with, it can provide better advice.
66+
67+
## SQL test generation
68+
69+
You can request that GitHub Copilot to generate SQL-based tests or assertions to verify query results or database state. Copilot can suggest appropriate testing frameworks based on your project type. To configure your testing environment, enter the /setupTests command in the chat input field and follow GitHub Copilot's guidance to configure your project.
70+
71+
GitHub Copilot can help you write tests for your application code by generating test code that covers your codebase. This includes unit tests, end-to-end tests, and tests for edge cases.
72+
73+
## Debug SQL errors
74+
75+
You can ask GitHub Copilot to help debug SQL errors or suggest fixes for common issues. For example, you can select a file or block of code and ask GitHub Copilot to locate and correct any syntax errors.
76+
77+
By having GitHub Copilot provide you with full table schema and indexes, you can then have GitHub Copilot generate representative queries against the tables and suggest any additional indexes, which might improve performance.
78+
79+
## GitHub Copilot prompt creation
80+
81+
You can use GitHub Copilot to generate prompts to create code that performs better than existing code. When interacting with GitHub Copilot, provide as much detail in the question as possible to increase the chance that the answer provided meets your requirements. To accomplish this:
82+
83+
- Have an understanding of the code. This understanding can be derived from existing interaction with GitHub Copilot.
84+
- Select the original code and open GitHub Copilot Chat.
85+
- Provide as much detail as possible. For example, you might provide GitHub Copilot chat with the following prompt:
86+
87+
_Given the following requirements:_
88+
_The database is SQLite and contains tables relevant to movie ratings (see the structure in complex.sql)._
89+
_The query should efficiently aggregate and return the top-rated movies by region, minimizing execution time and avoiding unnecessary operations (such as redundant CASTs, unnecessary JOINs, or SELECT DISTINCT if not needed)._
90+
_The result should include movie title, average rating, region, and any other relevant fields._
91+
_The query must complete in under 1.5 seconds on a large dataset.
92+
All business logic and correctness must be preserved as in the original complex.sql._
93+
_Write a high-performance SQL query that fulfills these requirements, and explain any optimizations you apply._

0 commit comments

Comments
 (0)