Skip to main content
April 2, 2026Dan Rodney/4 min read

Challenge - AI and SQL

Master SQL query writing with ChatGPT assistance

Challenge Overview

Transform your approach to SQL by leveraging ChatGPT as your intelligent query writing assistant. Focus on real business questions while AI handles the syntax.

Key Business Questions to Explore

Revenue Distribution Analysis

Analyze 2021 revenue sources across different states. Understand geographic performance and identify top-performing regions for strategic decision making.

Year-over-Year Growth

Compare revenue changes between 2020 and 2021. Calculate growth percentages and identify trends in business performance over time.

Custom Analysis Opportunities

Explore additional insights based on your database structure. Consider customer behavior, product performance, and seasonal trends.

ChatGPT SQL Query Process

1

Database Documentation

Take a screenshot of your database schema and upload it to ChatGPT. This eliminates the need to manually explain table structures and column names.

2

Specify SQL Flavor

Clearly indicate whether you're using PostgreSQL, SQL Server, or another database system to ensure compatible syntax generation.

3

Test and Validate

Run the generated code, verify results make logical sense, and review the query structure for accuracy and efficiency.

4

Manage Chat Sessions

Start new chat sessions for different queries to prevent context confusion and ensure focused, accurate responses.

ChatGPT for SQL Development

Pros
Eliminates manual typing of complex table and column names
Generates syntactically correct queries for specific database flavors
Speeds up query development process significantly
Helps explore different analytical approaches to business questions
Reduces syntax errors and debugging time
Cons
Requires validation of results and logic verification
May need context management across multiple queries
Generated queries might not always be optimally efficient
Database schema screenshots need to be current and complete

Screenshot Creation Methods

Database Tool

dBeaver Method

Use entity relationship diagram view, remove unnecessary tables, save as PNG image file

Direct Capture

Mac Quick Screenshot

Command+Shift+4 to select area, hold Control before releasing to copy to clipboard

SSMS Tool

SQL Server Management Studio

Create new database diagram, right-click to copy, paste through Paint if necessary

Pre-Challenge Preparation

0/4
Best Practice Reminder

Always perform a sanity check on generated results. Look at both the SQL code structure and the output data to ensure logical consistency with your business expectations.

This lesson is a preview from our SQL Course Online (includes software) and SQL Certification Online (includes software & exam). Enroll in a course for detailed lessons, live instructor support, and project-based training.

Now it's time to put theory into practice by leveraging ChatGPT to accelerate your SQL query development. As a Data Analyst, you should approach this with the mindset of uncovering actionable insights from your organization's data. The key is asking the right questions that drive business decisions.

Consider these essential analytical scenarios: First, revenue distribution analysis—in 2021, which geographic regions generated the highest revenue? How does performance vary across states, and what factors might explain these variations? Second, growth trajectory assessment—analyze year-over-year revenue changes by comparing 2020 to 2021 data. Are you seeing consistent growth, seasonal patterns, or concerning declines? Your challenge is to construct these queries using ChatGPT as your AI coding partner, transforming business questions into precise SQL statements without writing the code from scratch.

Beyond these foundational examples, consider exploring customer segmentation analysis, product performance metrics, seasonal trends, or operational efficiency indicators. The goal is developing your ability to translate business requirements into data queries while leveraging AI to handle the technical implementation details.

To maximize your success with ChatGPT, follow these critical best practices that will save you significant time and frustration. Rather than spending valuable time explaining your database schema in text, capture and upload a screenshot of your database structure. This visual context allows ChatGPT to understand your table relationships, column names, and data types instantly, producing queries that execute correctly on the first attempt.

Additionally, always specify your SQL dialect upfront. Whether you're working with PostgreSQL, SQL Server, MySQL, or another variant, each has unique syntax quirks and function libraries. This specification prevents ChatGPT from defaulting to generic SQL that may not work in your specific environment.


Quality assurance remains your responsibility, regardless of AI assistance. After receiving generated code, execute comprehensive testing: Run the query and verify it executes without errors. Examine the results critically—do the numbers align with your business knowledge? Review the code logic to ensure it's solving the intended problem. This verification process builds your SQL comprehension while catching potential AI misinterpretations.

Here's a crucial workflow tip: maintain separate ChatGPT conversations for distinct analytical tasks. Extended conversations can cause the AI to conflate different requirements or assume you're iterating on previous queries when you've moved to entirely new problems. Fresh conversations ensure clean context and more accurate results.

Let me walk you through efficient methods for capturing database schemas across different platforms. In DBeaver, double-click your target tables and navigate to the diagram view to access your entity relationship diagram. Clean up the visualization by removing irrelevant tables or views—simply select unwanted elements and right-click to delete them. Once you've isolated the relevant schema components, right-click the diagram and save it as a PNG image for upload to ChatGPT.

For Mac users seeking a streamlined approach, leverage the built-in screenshot functionality. After opening your database diagram in DBeaver, use Command+Shift+4 to activate the selection tool. Drag to select your desired area, then hold Control before releasing to copy directly to your clipboard rather than saving a file. Navigate to ChatGPT and paste with Command+V for immediate upload.


SQL Server Management Studio users can create focused database diagrams by right-clicking on Database Diagrams and selecting "New Database Diagram." Choose only the tables relevant to your current analysis to avoid overwhelming ChatGPT with unnecessary schema information. While you may not have save permissions for the diagram, you can still copy it to your clipboard by right-clicking and selecting copy. If direct pasting into ChatGPT fails, use Microsoft Paint as an intermediary—paste the diagram, then copy and paste it into ChatGPT.

Now it's time to tackle this challenge and discover how AI can transform your SQL development workflow. In our next session, we'll review effective approaches and discuss advanced techniques for maximizing ChatGPT's analytical capabilities.

Key Takeaways

1Use ChatGPT to accelerate SQL query writing by uploading database schema screenshots instead of manually describing table structures
2Always specify your SQL database flavor (PostgreSQL, SQL Server, etc.) to ensure syntactically correct query generation
3Focus on meaningful business questions like revenue distribution analysis and year-over-year growth comparisons
4Create new chat sessions for different queries to prevent context confusion and maintain focused AI responses
5Screenshots can be captured efficiently using database tools like dBeaver or system shortcuts like Command+Shift+4 on Mac
6SQL Server Management Studio users can create database diagrams and copy them to clipboard for easy sharing with ChatGPT
7Always test generated queries and validate both the code logic and result accuracy before relying on the output
8Consider exploring additional analytical opportunities beyond the provided examples based on your specific database content and business needs

RELATED ARTICLES