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
+41-64Lines changed: 41 additions & 64 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
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
7
## Use GitHub Copilot in SSMS
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
11
### Understand GitHub Copilot capabilities
12
12
@@ -15,23 +15,31 @@ GitHub Copilot provides several features for SQL Server development:
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
19
+
-**Custom instructions:** Define a custom instruction file and coding style preferences
21
20
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.
21
+
GitHub Copilot also offers these features via its chat:
22
+
23
+
-**Schema-aware suggestions:** Knows your exact table structures, columns, and data types
24
+
-**Query optimization:** Analyzes queries and suggests performance improvements
25
+
-**Natural language queries:** Converts questions into T-SQL based on your actual database
26
+
-**Explain queries:** Describes what existing queries do in plain language
27
+
-**Fix errors:** Provides context-aware suggestions when queries fail
28
+
-**Index recommendations:** Suggests indexes based on the missing index suggestions in the DMVs or in a query plan
29
+
30
+
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
31
24
32
### Enable GitHub Copilot in SSMS
25
33
26
34
To use GitHub Copilot in SQL Server Management Studio:
27
35
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
36
+
1. Ensure you have [SSMS 22](/ssms/download-sql-server-management-studio-ssms?azure-portal=true) installed
37
+
2. Install GitHub Copilot by selecting the **AI Assistance** workload in the [Visual Studio Installer](/ssms/github-copilot/installation-state?azure-portal=true)
30
38
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**
39
+
4. Configure your preferences in **Tools > Options > GitHub > Copilot** and **Tools > Options > Text Editor > Inline Suggestions**
32
40
33
41
> [!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.
42
+
> 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
43
36
44
### Write code with inline suggestions
37
45
@@ -40,13 +48,13 @@ GitHub Copilot provides suggestions as you type:
-- Get total sales by product category for last quarter
48
56
49
-
-- Copilot generates:
57
+
--GitHub Copilot generates:
50
58
SELECT
51
59
p.Category,
52
60
SUM(od.Quantity*od.UnitPrice) AS TotalSales
@@ -58,7 +66,7 @@ GROUP BY p.Category
58
66
ORDER BY TotalSales DESC;
59
67
```
60
68
61
-
The gray ghost text shows Copilot's suggestions. Press **Tab** to accept or **Esc** to dismiss.
69
+
The gray ghost text shows GitHub Copilot's suggestions. Press **Tab** to accept or **Esc** to dismiss.
62
70
63
71
### Generate stored procedures and functions
64
72
@@ -96,7 +104,7 @@ GitHub Copilot helps write queries to explore your database structure:
96
104
```sql
97
105
-- Show all foreign key relationships for Orders table
98
106
99
-
-- Copilot suggests:
107
+
--GitHub Copilot suggests:
100
108
SELECT
101
109
fk.nameAS ForeignKeyName,
102
110
OBJECT_NAME(fk.parent_object_id) AS TableName,
@@ -109,9 +117,9 @@ WHERE OBJECT_NAME(fk.parent_object_id) = 'Orders'
109
117
OR OBJECT_NAME(fk.referenced_object_id) ='Orders';
110
118
```
111
119
112
-
### Learn from your coding patterns
120
+
### Apply coding patterns of the current editor
113
121
114
-
GitHub Copilot adapts to your style over time. If you consistently use specific naming conventions, formatting, or patterns, Copilot incorporates them into suggestions:
122
+
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
123
116
124
```sql
117
125
-- If you typically write your queries like this:
@@ -122,7 +130,7 @@ SELECT
122
130
FROM Customers AS c
123
131
WHEREc.IsActive=1;
124
132
125
-
-- Copilot learns your style and suggests:
133
+
--GitHub Copilot follows your style and suggests:
126
134
SELECT
127
135
o.OrderID
128
136
,o.OrderDate
@@ -131,7 +139,7 @@ FROM Orders AS o
131
139
WHEREo.Status='Completed';
132
140
```
133
141
134
-
This personalization makes suggestions feel more natural and reduces the need for manual formatting.
142
+
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 |
151
+
|**Use meaningful names**| Descriptive table and column names help GitHub Copilot understand context |
144
152
|**Break down complex tasks**| Write multiple comments for complex procedures rather than one large block |
145
153
|**Review all suggestions**| Always validate generated code for correctness and security |
146
154
|**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.
155
+
|**Iterate on suggestions**| If the first suggestion isn't right, try rephrasing your comment |
168
156
169
157
### Query with natural language
170
158
171
159
Ask questions about your data using plain English:
172
160
173
161
```sql
174
-
-- Ask Copilot: "Show customers who placed more than 5 orders last month"
162
+
-- Ask GitHub Copilot: "Show customers who placed more than 5 orders last month"
175
163
176
-
-- Copilot generates (using your actual schema):
164
+
--GitHub Copilot generates (using your actual schema):
177
165
SELECT
178
166
c.CustomerID,
179
167
c.CustomerName,
@@ -188,11 +176,11 @@ HAVING COUNT(o.OrderID) > 5
188
176
ORDER BY OrderCount DESC;
189
177
```
190
178
191
-
Copilot knows your exact table and column names, ensuring the query works immediately.
179
+
Because GitHub Copilot connects to your database, it generates code that works with your specific schema.
192
180
193
181
### Optimize query performance
194
182
195
-
Copilot analyzes queries and suggests improvements:
183
+
GitHub Copilot analyzes queries and suggests improvements:
196
184
197
185
```sql
198
186
-- Select a slow query and ask: "How can I make this faster?"
@@ -205,7 +193,7 @@ LEFT JOIN OrderDetails od ON o.OrderID = od.OrderID
205
193
WHEREo.OrderDate>='2024-01-01'
206
194
GROUP BYc.CustomerName;
207
195
208
-
-- Copilot suggests:
196
+
--GitHub Copilot suggests:
209
197
-- 1. Change LEFT JOIN to INNER JOIN (WHERE filters out NULLs anyway)
210
198
-- 2. Add covering index: CREATE INDEX IX_Orders_Date ON Orders(OrderDate, CustomerID, OrderID)
211
199
-- 3. Consider indexed view for frequent aggregations
@@ -222,7 +210,7 @@ OPTION (RECOMPILE);
222
210
223
211
### Understand and fix errors
224
212
225
-
When queries fail, Copilot explains the issue and provides fixes:
213
+
When queries fail, GitHub Copilot explains the issue and provides fixes:
226
214
227
215
```sql
228
216
-- Query with error:
@@ -231,9 +219,9 @@ FROM Orders;
231
219
232
220
-- Error: Column 'Orders.CustomerName' is invalid in the select list
233
221
234
-
-- Ask Copilot: "What's wrong with this query?"
222
+
-- Ask GitHub Copilot: "What's wrong with this query?"
235
223
236
-
-- Copilot explains and fixes:
224
+
--GitHub Copilot explains and fixes:
237
225
/*
238
226
The error occurs because CustomerName is not in an aggregate function or GROUP BY clause.
239
227
When using aggregate functions like SUM(), all non-aggregated columns must be grouped.
@@ -245,19 +233,8 @@ FROM Orders
245
233
GROUP BY CustomerName;
246
234
```
247
235
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.
238
+
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
239
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.
240
+
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