Prerequisites

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.

Installation

Usage

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.