You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: learn-pr/wwl-data-ai/build-ai-solutions-sql-server/includes/2-copilot.md
+42-66Lines changed: 42 additions & 66 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,37 +1,44 @@
1
-
[SQL Server Management Studio (SSMS)](/sql/ssms/sql-server-management-studio-ssms?azure-portal=true)supports two AI-powered coding assistants that help you write, optimize, and troubleshoot [T-SQL](/sql/t-sql/language-reference?azure-portal=true) code. [GitHub Copilot](/ssms/github-copilot/overview?azure-portal=true) provides general coding assistance across multiple languages, while [Copilot](/ssms/copilot/copilot-in-ssms-overview?azure-portal=true) offers database-aware suggestions specific to your connected SQL Server instance.
1
+
[SQL Server Management Studio (SSMS)](/sql/ssms/sql-server-management-studio-ssms?azure-portal=true)includes [GitHub Copilot](/ssms/github-copilot/overview?azure-portal=true), an AI-powered assistant that helps you write, optimize, and troubleshoot [T-SQL](/sql/t-sql/language-reference?azure-portal=true) code. GitHub Copilot provides code completions in the query editor when writing T-SQL, and also provides a chat where you can use natural language to get help writing queries, ask questions about your database or environment, and get help with SQL issues. You should always use the latest release of SSMS (currently SSMS 22) as that is the GA release.
2
2
3
-
Both tools use large language models to accelerate database development. GitHub Copilot excels at code completion and pattern recognition across your entire codebase, while Copilot leverages your database schema, indexes, and statistics to provide contextually aware T-SQL assistance.
3
+
GitHub Copilot allows you to select a model, and available models vary based on your subscription. GitHub Copilot offers code completion and leverages your connection and database schema to provide context to the model and improve responses.
4
4
5
-
These AI assistants make database development more accessible and improve productivity for both new and experienced developers. Whether you're writing queries, debugging code, or optimizing performance, AI-powered assistance helps you focus on solving business problems rather than remembering syntax.
5
+
GitHub Copilot makes database development more accessible and improves productivity for both new and experienced developers. Whether you're writing queries, troubleshooting issues with your code, or optimizing performance, GitHub Copilot helps you focus on solving business problems rather than remembering syntax.
6
6
7
-
## Use GitHub Copilot in SSMS
7
+
## Understand GitHub Copilot in SQL Server Management Studio
8
8
9
-
[GitHub Copilot in SSMS](/ssms/github-copilot/overview?azure-portal=true) brings AI-powered code completionand generation to your database development workflow. As a general-purpose coding assistant, GitHub Copilot helps you write T-SQL faster by suggesting code as you type and generating entire queries from natural language comments.
9
+
[GitHub Copilot in SSMS](/ssms/github-copilot/overview?azure-portal=true) brings AI-powered code completion, generation, and chat to your database development workflow. GitHub Copilot helps you write T-SQL faster by suggesting code as you type, generating entire queries from natural language comments, and providing a chat experience where you can ask questions about your database and get help with SQL issues.
10
10
11
-
### Understand GitHub Copilot capabilities
11
+
### Explore GitHub Copilot capabilities
12
12
13
13
GitHub Copilot provides several features for SQL Server development:
14
14
15
15
-**Inline code completion:** Real-time suggestions as you write T-SQL code
16
16
-**Natural language to code:** Write comments describing your intent, get working queries
17
17
-**Multi-line suggestions:** Generate entire query blocks, procedures, or functions
18
-
-**Pattern recognition:** Learn from your coding style and common patterns in your workspace
19
-
-**Context-aware:** Considers the code you've already written in the current file
20
-
-**Multi-language support:** Works with T-SQL, PowerShell, Python, and other languages used in database projects
18
+
-**Context aware:** Understands the schema of the database to which you're connected
21
19
22
-
GitHub Copilot analyzes your current file, open tabs, and workspace to provide relevant suggestions. While it doesn't connect directly to your database, it recognizes T-SQL syntax patterns and common database development practices.
20
+
GitHub Copilot also offers these features via its chat:
21
+
22
+
-**Schema-aware suggestions:** Knows your exact table structures, columns, and data types
23
+
-**Query optimization:** Analyzes queries and suggests performance improvements
24
+
-**Natural language queries:** Converts questions into T-SQL based on the database to which you're connected
25
+
-**Explain queries:** Describes what existing queries do in plain language
26
+
-**Fix errors:** Provides context-aware suggestions when queries fail
27
+
-**Index recommendations:** Suggests indexes based on the missing index suggestions in the DMVs or in a query plan
28
+
29
+
GitHub Copilot also provides assistance troubleshooting query and database performance, along with answering questions about database maintenance, best practices, database and server configuration, and more.
23
30
24
31
### Enable GitHub Copilot in SSMS
25
32
26
33
To use GitHub Copilot in SQL Server Management Studio:
27
34
28
-
1. Ensure you have [SSMS 19.3](/ssms/download-sql-server-management-studio-ssms?azure-portal=true) or later installed
29
-
2. Install the [GitHub Copilot extension](https://docs.github.com/en/copilot/how-tos/set-up/install-copilot-extension) from the Extensions menu
35
+
1. Ensure you have [SSMS 22](/ssms/download-sql-server-management-studio-ssms?azure-portal=true) installed
36
+
2. Install GitHub Copilot by selecting the **AI Assistance** workload in the [Visual Studio Installer](/ssms/github-copilot/installation-state?azure-portal=true)
30
37
3. Sign in with your GitHub account that has an active [GitHub Copilot subscription](https://github.com/features/copilot/plans?azure-portal=true)
31
-
4. Configure your preferences in **Tools > Options > GitHub Copilot**
38
+
4. Configure your preferences in **Tools > Options > GitHub > Copilot** and **Tools > Options > Text Editor > Inline Suggestions**
32
39
33
40
> [!NOTE]
34
-
> GitHub Copilot requires a paid subscription (Individual, Business, or Enterprise). Some organizations provide GitHub Copilot for their developers as part of their development tools license.
41
+
> GitHub Copilot requires a subscription (Individual, Business, or Enterprise). Some organizations provide GitHub Copilot for their developers as part of their development tools license. A GitHub Copilot subscription can also be used with Visual Studio and VS Code.
35
42
36
43
### Write code with inline suggestions
37
44
@@ -40,13 +47,13 @@ GitHub Copilot provides suggestions as you type:
-- Get total sales by product category for last quarter
48
55
49
-
-- Copilot generates:
56
+
--GitHub Copilot generates:
50
57
SELECT
51
58
p.Category,
52
59
SUM(od.Quantity*od.UnitPrice) AS TotalSales
@@ -58,7 +65,7 @@ GROUP BY p.Category
58
65
ORDER BY TotalSales DESC;
59
66
```
60
67
61
-
The gray ghost text shows Copilot's suggestions. Press **Tab** to accept or **Esc** to dismiss.
68
+
The gray ghost text shows GitHub Copilot's suggestions. Press **Tab** to accept or **Esc** to dismiss.
62
69
63
70
### Generate stored procedures and functions
64
71
@@ -96,7 +103,7 @@ GitHub Copilot helps write queries to explore your database structure:
96
103
```sql
97
104
-- Show all foreign key relationships for Orders table
98
105
99
-
-- Copilot suggests:
106
+
--GitHub Copilot suggests:
100
107
SELECT
101
108
fk.nameAS ForeignKeyName,
102
109
OBJECT_NAME(fk.parent_object_id) AS TableName,
@@ -109,9 +116,9 @@ WHERE OBJECT_NAME(fk.parent_object_id) = 'Orders'
109
116
OR OBJECT_NAME(fk.referenced_object_id) ='Orders';
110
117
```
111
118
112
-
### Learn from your coding patterns
119
+
### Apply coding patterns of the current editor
113
120
114
-
GitHub Copilot adapts to your style over time. If you consistently use specific naming conventions, formatting, or patterns, Copilot incorporates them into suggestions:
121
+
GitHub Copilot follows the coding patterns in your current editor. If you use specific naming conventions, formatting, or patterns, GitHub Copilot incorporates them into suggestions:
115
122
116
123
```sql
117
124
-- If you typically write your queries like this:
@@ -122,7 +129,7 @@ SELECT
122
129
FROM Customers AS c
123
130
WHEREc.IsActive=1;
124
131
125
-
-- Copilot learns your style and suggests:
132
+
--GitHub Copilot follows your style and suggests:
126
133
SELECT
127
134
o.OrderID
128
135
,o.OrderDate
@@ -131,7 +138,7 @@ FROM Orders AS o
131
138
WHEREo.Status='Completed';
132
139
```
133
140
134
-
This personalization makes suggestions feel more natural and reduces the need for manual formatting.
141
+
This consistency makes suggestions feel more natural and reduces the need for manual formatting.
|**Write descriptive comments**| Clear, specific comments produce better code suggestions |
143
-
|**Use meaningful names**| Descriptive table and column names help Copilot understand context |
150
+
|**Use meaningful names**| Descriptive table and column names help GitHub Copilot understand context |
144
151
|**Break down complex tasks**| Write multiple comments for complex procedures rather than one large block |
145
152
|**Review all suggestions**| Always validate generated code for correctness and security |
146
153
|**Provide examples**| Include sample data or expected output in comments |
147
-
|**Keep context nearby**| Open related files or schemas to give Copilot more context |
148
-
|**Iterate on suggestions**| If the first suggestion isn't quite right, try rephrasing your comment |
149
-
150
-
## Use Copilot in SSMS
151
-
152
-
[Copilot in SSMS](/ssms/copilot/copilot-in-ssms-overview?azure-portal=true) provides database-aware AI assistance that connects directly to your SQL Server instance. Unlike GitHub Copilot, Copilot has access to your database schema, indexes, statistics, and metadata, enabling more contextually accurate T-SQL suggestions.
153
-
154
-
:::image type="content" source="../media/ssms.png" alt-text="Screenshot showing GitHub Copilot in SQL Server Management Studio with AI-powered code completion." lightbox="../media/ssms.png" border="false":::
155
-
156
-
### Understand Copilot capabilities
157
-
158
-
Copilot offers database-specific features:
159
-
160
-
-**Schema-aware suggestions:** Knows your exact table structures, columns, and data types
161
-
-**Query optimization:** Analyzes execution plans and suggests performance improvements
162
-
-**Natural language queries:** Converts questions into T-SQL based on your actual database
163
-
-**Explain queries:** Describes what existing queries do in plain language
164
-
-**Fix errors:** Provides context-aware suggestions when queries fail
165
-
-**Index recommendations:** Suggests indexes based on your database statistics
166
-
167
-
Because Copilot connects to your database, it generates code that works with your specific schema without modification.
154
+
|**Iterate on suggestions**| If the first suggestion isn't right, try rephrasing your comment |
168
155
169
156
### Query with natural language
170
157
171
158
Ask questions about your data using plain English:
172
159
173
160
```sql
174
-
-- Ask Copilot: "Show customers who placed more than 5 orders last month"
161
+
-- Ask GitHub Copilot: "Show customers who placed more than 5 orders last month"
175
162
176
-
-- Copilot generates (using your actual schema):
163
+
--GitHub Copilot generates (using your actual schema):
177
164
SELECT
178
165
c.CustomerID,
179
166
c.CustomerName,
@@ -188,11 +175,11 @@ HAVING COUNT(o.OrderID) > 5
188
175
ORDER BY OrderCount DESC;
189
176
```
190
177
191
-
Copilot knows your exact table and column names, ensuring the query works immediately.
178
+
Because GitHub Copilot connects to your database, it generates code that works with your specific schema.
192
179
193
180
### Optimize query performance
194
181
195
-
Copilot analyzes queries and suggests improvements:
182
+
GitHub Copilot analyzes queries and suggests improvements:
196
183
197
184
```sql
198
185
-- Select a slow query and ask: "How can I make this faster?"
@@ -205,7 +192,7 @@ LEFT JOIN OrderDetails od ON o.OrderID = od.OrderID
205
192
WHEREo.OrderDate>='2024-01-01'
206
193
GROUP BYc.CustomerName;
207
194
208
-
-- Copilot suggests:
195
+
--GitHub Copilot suggests:
209
196
-- 1. Change LEFT JOIN to INNER JOIN (WHERE filters out NULLs anyway)
210
197
-- 2. Add covering index: CREATE INDEX IX_Orders_Date ON Orders(OrderDate, CustomerID, OrderID)
211
198
-- 3. Consider indexed view for frequent aggregations
@@ -222,7 +209,7 @@ OPTION (RECOMPILE);
222
209
223
210
### Understand and fix errors
224
211
225
-
When queries fail, Copilot explains the issue and provides fixes:
212
+
When queries fail, GitHub Copilot explains the issue and provides fixes:
226
213
227
214
```sql
228
215
-- Query with error:
@@ -231,9 +218,9 @@ FROM Orders;
231
218
232
219
-- Error: Column 'Orders.CustomerName' is invalid in the select list
233
220
234
-
-- Ask Copilot: "What's wrong with this query?"
221
+
-- Ask GitHub Copilot: "What's wrong with this query?"
235
222
236
-
-- Copilot explains and fixes:
223
+
--GitHub Copilot explains and fixes:
237
224
/*
238
225
The error occurs because CustomerName is not in an aggregate function or GROUP BY clause.
239
226
When using aggregate functions like SUM(), all non-aggregated columns must be grouped.
@@ -245,19 +232,8 @@ FROM Orders
245
232
GROUP BY CustomerName;
246
233
```
247
234
248
-
### Choose the right tool
249
-
250
-
Both tools offer value for SQL Server development:
Use **GitHub Copilot** for general T-SQL development, multi-language projects, and code completion across your entire codebase. Use **Copilot** for database-specific tasks where schema awareness, query optimization, and direct database interaction provide better results.
237
+
The GitHub Copilot chat window works without a database connection, but it's much more valuable when you have a query editor open and connected to a database. Use GitHub Copilot for general T-SQL development, code completion in the editor, understanding your database and server, query optimization, and more.
262
238
263
-
Many developers use both: GitHub Copilot for day-to-day coding and Copilot when working with specific database instances. Together, these AI assistants accelerate database development while maintaining code quality and security standards.
239
+
Developers can use GitHub Copilot for day-to-day coding and to answer specific database questions, helping accelerate database development while maintaining code quality and leveraging best practices.
0 commit comments