Installing and Using GitHub Copilot in Azure Data Studio

Prerequisites

  • Azure Data Studio is installed on your machine.
  • A GitHub account.

Use of Azure Data Studio

Azure Data Studio is a tool designed for data professionals to manage and work with databases. It is useful for.

  • Writing and running SQL queries.
  • Managing SQL Server and Azure SQL databases.
  • Creating and using Jupyter Notebooks.
  • Exploring and managing database objects.
  • Utilizing built-in features like IntelliSense, code snippets, and source control integration.

Installation

  • Open Azure Data Studio: Launch Azure Data Studio on your machine.
  • Open Extensions View: Click on the Extensions icon in the Activity Bar on the side of the window or press Ctrl+Shift+X.
  • Search for GitHub Copilot: In the Extensions view, type "GitHub Copilot" in the search box.
  • Install GitHub Copilot: Find the GitHub Copilot extension in the search results and click the Install button.
  • Sign In to GitHub: After installation, you will be prompted to sign in to GitHub. Follow the on-screen instructions to authenticate with your GitHub account.

Usage

  • Open a New File: Open a new or existing file in Azure Data Studio where you want to use GitHub Copilot.
  • Start Typing: Begin typing your SQL code. GitHub Copilot will start suggesting code completions and snippets.

Example

Let’s say you're writing a SQL query to retrieve data from a Customer table. As you start typing.

SELECT * 
FROM Customers 
WHERE 

GitHub Copilot may automatically suggest.

SELECT * 
FROM Customers 
WHERE Country = 'USA';

This saves you time by completing the code for a typical scenario. You can accept the suggestion by pressing Tab.

Accept Suggestions: Use Tab to accept a suggestion or Esc to dismiss it. You can also use the arrow keys to navigate through multiple suggestions.

Example

If you need to filter customers who have been active in the past year, you could type.

SELECT * 
FROM Customers 
WHERE LastActiveDate > [your_date_here];

Copilot might suggest.

SELECT * 
FROM Customers 
WHERE LastActiveDate > '2023-01-01';

You can easily accept this suggestion to continue your query.

Invoke Copilot Manually: You can manually invoke GitHub Copilot by pressing Ctrl+Enter to see suggestions for the current line.

Example

While working on a more complex query, such as an aggregate query to get the number of orders per customer.

SELECT CustomerID, COUNT(OrderID) 
FROM Orders 
GROUP BY CustomerID;

If you’re unsure about writing the correct JOIN statement for fetching customer data, press Ctrl+Enter, and Copilot might suggest the following.

SELECT 
    Customers.CustomerName, 
    COUNT(Orders.OrderID) 
FROM 
    Orders 
JOIN 
    Customers 
    ON Orders.CustomerID = Customers.CustomerID 
GROUP BY 
    Customers.CustomerName;

Real-Time Example: Enhancing SQL Query Generation

Suppose you're tasked with creating a complex report involving multiple tables and aggregate functions. Here's how Copilot can assist.

  1. Scenario: You need to generate a report of sales by region and product category.
  2. Manual Input: You begin typing the SQL query like this.
    SELECT 
        Region, 
        ProductCategory, 
        SUM(SalesAmount)
    
  3. Copilot Suggestion: As soon as you start typing, Copilot suggests the following.
    SELECT 
        Region, 
        ProductCategory, 
        SUM(SalesAmount) 
    FROM 
        Sales 
    JOIN 
        Products 
        ON Sales.ProductID = Products.ProductID 
    JOIN 
        Regions 
        ON Sales.RegionID = Regions.RegionID 
    GROUP BY 
        Region, 
        ProductCategory;
    
  4. Acceptance: You simply press Tab, and Copilot completes the query for you, saving time and effort in writing complex SQL joins and aggregations.

Hope this article is helpful for you.