How I Use ChatGPT & GitHub Copilot in My Projects
Core Premise: Artificial intelligence tools are force multipliers for data professionals, but their efficacy depends on developer discipline, proper tool selection, and structural prompt design. Combining high-level contextual reasoning (ChatGPT) with real-time inline coding assistance (GitHub Copilot) accelerates development while ensuring high-quality, production-ready SQL and database architecture.
1. Developer Growth & The Core AI Discipline
While AI tools dramatically increase development velocity, over-relying on them during early problem-solving hinders developer growth. Real expertise is forged through the cognitive friction of debugging complex tasks independently.
The Rules of Engagement with AI
- Plow Through First: Always attempt to architect and write the code independently when tackling complex tasks. The "struggle phase" is where real comprehension occurs.
- Skip-Step Risk: Jumping to AI too quickly skips essential learning loops, rendering you incapable of recognizing when the AI provides hallucinated, inefficient, or flat-out incorrect code.
- Audit Readiness: Treat AI outputs as non-binding suggestions. Your job as a developer is to critically evaluate performance, security, and logic before committing code to production.
2. Core Mental Models: ChatGPT vs. GitHub Copilot
Understanding the technical architecture behind generative AI tools clarifies when and where to deploy them.
Decoding GPT
GPT stands for Generative Pre-trained Transformer:
- Generative: The underlying probabilistic model can generate entirely new content (text, code, structured JSON/SQL) rather than just retrieving pre-existing documents.
- Pre-trained: The model has been pre-conditioned on massive textual and public repository data prior to user interaction.
- Transformer: A neural network architecture that utilizes self-attention mechanisms to process input sentences in parallel, catching subtle context and long-range dependencies accurately.
Tool Architecture & Direct Comparison
Both tools share foundational models developed by OpenAI, but their fine-tuning and operational delivery models diverge significantly:
3. Workflow Division: Task-to-Tool Mapping
No single AI tool covers the full spectrum of activities required in a enterprise data project. Optimal performance requires fluidly jumping between ChatGPT and GitHub Copilot depending on task granularity.
Strategic Task Division
Deploy ChatGPT For:
- High-Level Brainstorming: Exploring alternative architectural patterns for data pipelines.
- Project Roadmap & Planning: Breaking monolithic project requirements into structured milestones.
- Domain Research: Learning new cloud analytics services or unfamiliar database capabilities.
- Documentation & Business Rules: Generating human-readable project summaries and documentation tables.
- Architecture Evaluation: Comparing schema paradigms (e.g., Star Schema vs. Snowflake Schema vs. Data Vault).
Deploy GitHub Copilot For:
- Real-time Autocompletion: Predicting select queries, join conditions, and window functions while typing.
- Inline Refactoring: Optimizing highlighted code blocks directly within the file editor.
- Inline Syntax Generation: Converting quick single-line comments directly into working SQL statements.
- Targeted Code Styling: Formatting active code files according to standard repository rules.
4. GitHub Copilot in Practice: VS Code Integration & Shortcuts
GitHub Copilot acts as an inline pair-programmer. Once authenticated in Visual Studio Code, it runs continuously in the background, projecting suggestions directly into the editor.
Key VS Code Interactions & Keyboard Shortcuts
1. Ghost Text Autocompletion
As you type SQL code, Copilot generates gray, semi-transparent text (Ghost Text).
- Press
Tabto accept the full suggestion. - Press
Ctrl+Right Arrowto selectively accept suggestion word-by-word.
2. Comment-Driven Code Generation
Type a plain-language intent as a standard SQL comment, then hit enter:
-- Select top 3 customers based on total order score
Copilot will immediately evaluate the comment and prompt the correct query structure:
SELECT TOP 3
customer_id,
customer_name,
score
FROM customers
ORDER BY score DESC;
3. Multi-Variant Solutions Drawer (Ctrl + Enter)
When facing complex operations (e.g., customer sales ranking), hit Ctrl + Enter to open the Copilot Synthesis Panel. Copilot will construct up to 10 distinct approach variations (CTEs, Subqueries, Window Functions) in a side panel, allowing you to select and click Accept Suggestion.
4. Inline Chat & Targeted Modifications (Ctrl + I)
Highlight a block of code and hit Ctrl + I to open an inline chat overlay.
- Example Prompt:
"Join this query with sales_orders table on customer_id" - Copilot evaluates local editor context (known schema tables, column definitions) and injects the updated query inline, displaying a green/red diff comparison prior to final acceptance.
5. Automated Debugging & The Sparkle Icon
When VS Code flags a syntax or logic error (red squiggly line):
- Hover over the error or right-click the highlighted code.
- Select Copilot -> Explain This or Fix This.
- Alternatively, click the Yellow Sparkle Icon in the gutter to apply an automated patch.
5. Anatomy of an Effective AI Prompt
Vague inputs produce generic, unhelpful outputs. Constructing enterprise-grade prompts requires a modular structural framework.
The 5 Modular Prompt Components
Naive vs. Production-Grade Prompting
Naive Prompt (Poor Results)
"Explain SQL window functions."
Why it fails: Lacks database dialect context, target audience skill level, functional specs, or structural layout requirements.
Production-Grade Structured Prompt (High-Fidelity Results)
[ROLE]
Act as a Senior Database Architect and SQL Performance Tuning Expert.
[CONTEXT]
I am a Data Analyst working with a Microsoft SQL Server enterprise database. I am working on analytical reporting queries over a table containing tens of millions of sales transactions.
[TASK]
Explain the concept of SQL Window Functions and demonstrate how to apply them for analytical reporting.
[SPECIFICATIONS]
1. Explain the operational difference between window functions and GROUP BY.
2. Provide the generic syntax structure (OVER, PARTITION BY, ORDER BY).
3. Demonstrate the top 3 production use cases (Ranking, Running Totals, Moving Averages).
4. Include clean T-SQL code snippets for each use case.
5. Highlight performance pitfalls when executing over large tables.
[TONE]
Professional, precise, structured, and direct.
6. ChatGPT Prompts for SQL Engineering (Part 1: Code & Architecture)
Prompt 1: Multi-Variant Task Solution & Evaluation
Act as an SQL Developer. I am using SQL Server.
Database Schema:
- Table 'orders': order_id (INT), customer_id (INT), sales_amount (DECIMAL), order_date (DATE)
- Table 'customers': customer_id (INT), full_name (VARCHAR), country (VARCHAR)
Task:
Write an SQL script to rank customers based on their total order sales amount.
Specifications:
1. Output fields: customer_id, full_name, country, total_sales, sales_rank.
2. Include brief comments on complex parts (avoid commenting obvious code).
3. Write THREE distinct query variants to achieve this task (e.g., using CTEs, Subqueries, and direct Window Functions).
4. Evaluate all 3 versions for Readability vs. Performance trade-offs.
Output Code Snippet Generated:
-- Version 1: Common Table Expression (CTE) - High Readability
WITH CustomerSales AS (
SELECT
c.customer_id,
c.full_name,
c.country,
SUM(o.sales_amount) AS total_sales
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
GROUP BY c.customer_id, c.full_name, c.country
)
SELECT
customer_id,
full_name,
country,
total_sales,
DENSE_RANK() OVER (ORDER BY total_sales DESC) AS sales_rank
FROM CustomerSales;
-- Version 2: Subquery Approach - Intermediate
SELECT
cs.customer_id,
cs.full_name,
cs.country,
cs.total_sales,
DENSE_RANK() OVER (ORDER BY cs.total_sales DESC) AS sales_rank
FROM (
SELECT
c.customer_id,
c.full_name,
c.country,
SUM(o.sales_amount) AS total_sales
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
GROUP BY c.customer_id, c.full_name, c.country
) cs;
-- Version 3: Direct Group By with Window Function - Maximum Compactness
SELECT
c.customer_id,
c.full_name,
c.country,
SUM(o.sales_amount) AS total_sales,
DENSE_RANK() OVER (ORDER BY SUM(o.sales_amount) DESC) AS sales_rank
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
GROUP BY c.customer_id, c.full_name, c.country;
Prompt 2: Code Refactoring & CTE Consolidation
The following SQL Server query is long, hard to read, and contains multiple CTEs that seem redundant.
Tasks:
1. Refactor the script to improve overall readability.
2. Identify and eliminate redundant CTEs or subqueries, consolidating the logic.
3. Keep comments concise and focused on business rules.
4. Explain each architectural improvement step-by-step so I can avoid these issues in the future.
Input Query:
[Paste raw script here]
Prompt 3: SQL Query Performance Optimization
I have a slow-running SQL Server query executing against a table with millions of rows.
Task:
1. Review the query for anti-patterns and performance bottlenecks.
2. Provide an optimized rewrite following SQL performance best practices.
3. Explain each optimization applied (e.g., avoiding non-sargable functions in WHERE clauses, replacing correlated subqueries, minimizing scan operators).
Input Query:
SELECT order_id, customer_id, sales_amount
FROM orders
WHERE LOWER(status) = 'completed'
AND YEAR(order_date) = 2023
AND customer_id IN (SELECT customer_id FROM customers WHERE country = 'USA');
Optimization Analysis & Rewritten SQL:
Issues Identified:
LOWER(status)andYEAR(order_date)render theWHEREclause non-sargable, preventing index usage and forcing full table scans.IN (SELECT...)can cause inefficient nested loop evaluations depending on statistics.
-- Optimized Production Query
SELECT
o.order_id,
o.customer_id,
o.sales_amount
FROM orders o
WHERE o.status = 'completed' -- Assumes standard casing or case-insensitive collation
AND o.order_date >= '2023-01-01'
AND o.order_date < '2024-01-01' -- Sargable date-range filtering allows index seek
AND EXISTS (
SELECT 1
FROM customers c
WHERE c.customer_id = o.customer_id
AND c.country = 'USA'
);
Prompt 4: Execution Plan Diagnostics
I am attaching/pasting the text execution plan for an SQL Server query.
Task:
1. Walk through the execution flow step-by-step.
2. Identify major performance bottlenecks (e.g., Table Scans, Index Scans vs Seeks, Implicit Conversions, Heavy Hash Spills, or Nested Loop bottlenecks).
3. Provide precise schema or query index modifications to eliminate the identified bottlenecks.
Execution Plan Details / Context:
- Table 'orders_archive' shows a Table Scan taking 82% of batch cost.
- Join operator indicates a Nested Loop between two large datasets.
7. ChatGPT Prompts for SQL Engineering (Part 2: Debugging & Schema)
Prompt 5: Error Debugging & Root-Cause Analysis
My SQL Server query fails upon execution.
Context:
Error Code / Message:
"Msg 8120, Level 16, State 1: Column 'sales.orders.sales_amount' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."
Task:
1. Explain the underlying root cause of this error in plain terms.
2. Pinpoint the exact location in the query triggering the issue.
3. Provide the corrected SQL script.
Input Query:
SELECT customer_id, country, sales_amount, SUM(sales_amount)
FROM sales.orders
GROUP BY customer_id;
Prompt 6: Result & Logic Explanation (e.g., Recursive CTEs)
I inherited an SQL script containing a complex logic pattern (e.g., Recursive CTE) and need to understand how the output dataset is constructed.
Task:
1. Break down how the database engine executes this query step-by-step.
2. Explain the anchor evaluation vs. the recursive iteration process.
3. Identify the explicit exit/termination condition to explain how infinite loops are prevented.
Input Query:
WITH RECURSIVE SequenceGenerator AS (
SELECT 1 AS number
UNION ALL
SELECT number + 1
FROM SequenceGenerator
WHERE number < 20
)
SELECT number FROM SequenceGenerator;
Prompt 7: Code Formatting & Styling Standardization
Re-style the following SQL script to match enterprise standard readability guidelines.
Specifications:
1. Capitalize all standard SQL keywords (SELECT, FROM, WHERE, JOIN, OVER, CTE).
2. Align column aliases consistently.
3. Maintain compact formatting without injecting unnecessary double newlines.
4. Standardize string concatenation and conditional expressions.
Input Query:
[Paste messy code here]
Prompt 8: Automated Documentation & Inline Commenting
The following analytical SQL script lacks documentation and comments.
Task:
1. Add a high-level header block comment detailing the overall business purpose of the script.
2. Add inline comments strictly where business logic or non-obvious transformations occur (do NOT comment basic syntax).
3. Output a markdown documentation block summarizing:
- Input Tables & Dependencies
- Business Logic Rules Applied
- Target Output Metrics
Input Query:
[Paste query here]
Prompt 9: DDL & Database Schema Optimization
Optimize the following SQL Server DDL script for data integrity, performance, and naming consistency.
Task:
1. **Naming Conventions**: Check for consistent casing (PascalCase / snake_case).
2. **Data Types**: Suggest optimal types (e.g., replacement of generic FLOAT/INT with DECIMAL/SMALLINT where appropriate).
3. **Data Integrity**: Add essential constraints (PRIMARY KEY, FOREIGN KEY, CHECK constraints, NOT NULL).
4. **Indexing Strategy**: Recommend non-clustered indexes for foreign keys and common query predicates.
Input DDL:
CREATE TABLE employees (
emp_id INT,
first_name VARCHAR(50),
gender CHAR(1),
salary FLOAT,
birth_date DATE
);
Output Optimized DDL:
CREATE TABLE dbo.Employees (
EmployeeID INT IDENTITY(1,1) NOT NULL,
FirstName NVARCHAR(50) NOT NULL,
Gender CHAR(1) NOT NULL,
Salary DECIMAL(12, 2) NOT NULL,
BirthDate DATE NOT NULL,
-- Constraints
CONSTRAINT PK_Employees_EmployeeID PRIMARY KEY CLUSTERED (EmployeeID),
CONSTRAINT CK_Employees_Gender CHECK (Gender IN ('M', 'F', 'U')),
CONSTRAINT CK_Employees_Salary CHECK (Salary >= 0.00),
CONSTRAINT CK_Employees_BirthDate CHECK (BirthDate <= GETDATE())
);
-- Indexing Recommendation for performance
CREATE NONCLUSTERED INDEX IX_Employees_BirthDate
ON dbo.Employees(BirthDate);
Prompt 10: Relational Synthetic Test Data Generation
Prompt 11: Cross-Dialect SQL Migration (SQL Server to MySQL)
Output MySQL Translated Query:
SELECT
customer_id,
COALESCE(middle_name, '') AS middle_name,
CONCAT(first_name, ' ', last_name) AS full_name,
NOW() AS query_time
FROM customers
LIMIT 10;
8. ChatGPT Prompts for Learning, Concept Mastery & Interview Prep
Prompt 12: Personalized Learning Roadmap Generation
Act as an Expert Data Engineering Instructor.
Task:
Create a comprehensive, 4-phase structured learning roadmap for mastering SQL tailored specifically for Data Analytics.
Specifications:
1. Break down into 4 clear phases: Fundamentals, Intermediate, Advanced Analytics, Real-World Scenarios.
2. Under each phase, list core concepts, key functions, and practical project tasks.
3. Focus heavily on analytical operations (aggregations, joins, window functions, CTEs).
Prompt 13: Concept Explanation with Mental Hooks (Window Functions Analogy)
Explain the concept of SQL Window Functions to a beginner student.
Specifications:
1. Provide a real-world non-technical mental analogy to make the concept intuitive.
2. Explain *why* traditional GROUP BY queries are insufficient for row-level detail retainment.
3. Show a basic syntax breakdown (OVER, PARTITION BY, ORDER BY).
Analogy Output:
Real-Life Analogy: Teacher Grading Students
Imagine a high school teacher grading final exam papers for a class:
GROUP BYAggregation: The teacher takes all exam papers, stacks them into group piles by grade level, burns the individual papers, and writes down only the average score of each grade level on a whiteboard. Individual student scores are lost forever.Window Functions: The teacher holds each individual student's paper in hand, but looks across the entire room (the "window") to calculate the class average or rank, writing that student's individual rank directly on their own paper. The individual row detail is completely preserved alongside the calculated summary metrics!
Prompt 14: Tabular Concept Comparison (Window Functions vs GROUP BY)
Compare SQL Window Functions versus GROUP BY Aggregations.
Task:
1. Explain structural differences in handling row detail.
2. Detail when to use which pattern.
3. Summarize all differences in a clear Markdown table.
Synthesized Comparison Output
Prompt 15: Interactive SQL Practice & Mock Technical Interviews
Practice Prompt Strategy
Act as an SQL Technical Interviewer and Practice Coach.
Task:
Conduct an interactive SQL mock technical interview with me focusing on Window Functions and Joins.
Rules of Interaction:
1. Present ONE question at a time.
2. Provide a small, schema sample dataset for context.
3. Wait for my code submission before moving forward.
4. Evaluate my answer strictly: analyze correctness, performance, and edge-case vulnerabilities.
5. Provide a score, suggest improvements, and ask if I am ready for the next question.
Example Simulation Walkthrough
[Interviewer AI]:
Question 1: Given a 'sales' table (sales_id, employee_id, amount, sale_date),
write a query to calculate each employee's running total of sales over time.
[User Submission]:
SELECT
employee_id,
sale_date,
amount,
SUM(amount) OVER (PARTITION BY employee_id) AS running_total
FROM sales;
[Interviewer AI Evaluation]:
Result: INCORRECT.
Feedback: You applied `PARTITION BY employee_id`, which calculates the grand total
sales per employee across all time, but missed the dynamic running accumulator!
To create a running total, you must include an `ORDER BY` clause inside the OVER() window.
Corrected Query:
SELECT
employee_id,
sale_date,
amount,
SUM(amount) OVER (
PARTITION BY employee_id
ORDER BY sale_date
) AS running_total
FROM sales;
Ready for Question 2? (Yes/No)
Summary and Key Takeaways
- Maintain Problem-Solving Discipline: Never jump to AI immediately upon encountering a bug or complex task. Solve it manually first to build deep domain skills, using AI only when stuck or validating ideas.
- Understand Tool Architectural Differences: Use ChatGPT as a macro-level advisor for architectural design, complex execution plans, learning, and prompt-driven schema tuning. Use GitHub Copilot as a micro-level pair programmer for real-time inline coding, formatting, and quick syntax completions.
- Master Copilot Keyboard Shortcuts: Leverage
Tabfor full ghost text completion,Ctrl+Right Arrowfor partial completions,Ctrl+Enterfor alternative solution matrices, andCtrl+Ifor targeted inline edits within VS Code. - Structure Engineering Prompts: Build prompts using the 5 core components (Role, Context, Task, Specifications, Tone). Never submit generic 3-word prompts if you expect enterprise-ready code.
- Audit AI Code for Sargability and Performance: Generative models frequently write non-sargable functions inside
WHEREclauses (e.g.,LOWER(),YEAR()) or introduce inefficient correlated subqueries. Always inspect execution paths manually. - Leverage AI for Database Operations: Use structured prompts to optimize DDL scripts with real constraints (
CHECK,FOREIGN KEY), generate schema-compliant synthetic test datasets, and accurately migrate queries between SQL dialects (e.g., T-SQL to MySQL). - Accelerate Skill Acquisition: Transform ChatGPT into a high-touch personalized tutor by requesting structural frameworks, mental analogies, tabular concept comparisons, and real-time interactive mock interviews.