5 Scenarios Where SQL Generated by an LLM Takes Down a Production Database

SQL written by an LLM runs without errors. That’s what makes it more dangerous. We’ll reproduce in Docker MySQL how revenue gets inflated threefold, a one-day query reads all 300,000 rows in a table, and the contact details of withdrawn members end up mixed into a list, then organize the findings into a review checklist to catch these issues before connecting to the production database.

40 learners are taking this course

Level Basic

Course period Unlimited

SQL
SQL
MySQL
MySQL
LLM
LLM
SQL
SQL
MySQL
MySQL
LLM
LLM
Thumbnail

What you will gain after the course

  • Identify one-to-many joins in aggregation SQL generated by an LLM, aggregate them first, rewrite the SQL to join the aggregated results, and verify it using reconciliation totals.

  • Use EXPLAIN’s type and rows, along with the number of rows read, to identify and fix conditions that prevent index usage (wrapping columns in functions, type conversions, and leading wildcards).

  • Prevent SQL queries from reading the entire production database with row limits, sort indexes, and execution time limits.

  • Filter out SELECT *, missing masking, and the inclusion of withdrawn or non-consenting members; protect personal data tables with safe views and permissions.

  • Fix conditions that silently go wrong because of NOT IN and NULL, BETWEEN end dates, the final second, and the time difference between UTC and Korea time.

  • Classify LLM SQL as pass, hold, or rewrite using a five-scenario review checklist.

The Most Dangerous SQL Is the SQL That Runs Without Errors — Five Scenarios and a Review Checklist for Catching LLM-Generated SQL Before It Hits the Production Database

SQL written by an LLM runs without errors. That’s what makes it even more dangerous. We reproduce firsthand in Docker MySQL scenarios where sales are inflated threefold, a query for a single day reads all 300,000 rows in a table, and contact information for former members gets mixed into a list. Then we organize them into a review decision table to catch these issues before connecting the SQL to a production database.

All the numbers shown are original results from queries actually run on Docker MySQL on a notebook. Of the 145 slides, 53 (about 36%) are actual terminal screenshots—not tables redrawn as slides—and each lesson includes 7–8 of them. In each lesson, the same data is counted in two ways for comparison, following this sequence: request → LLM SQL → execution result → review points → corrected SQL and result → review questions.

By the end of this lesson, you will be able to

  • Find one-to-many joins in aggregation SQL generated by an LLM, fix the SQL by aggregating first and then joining, and verify it by comparing totals.

  • Use EXPLAIN’s type and rows, along with the number of rows read, to identify and fix conditions that bypass indexes (wrapping columns in functions, type conversions, and leading wildcards).

  • Prevent SQL queries from reading the entire production database by limiting result counts, using sort indexes, and imposing execution time limits.

  • Filter out SELECT *, missing masking, and the inclusion of withdrawn or non-consenting members, and protect personal information tables with secure views and permissions.

  • Fix conditions that can silently produce incorrect results due to NOT IN and NULL, the end date in BETWEEN, the final second of the day, and the time difference between UTC and Korea Standard Time.

  • Use a five-scenario review checklist to classify LLM-generated SQL as pass, hold, or rewrite.

Recommended for:

  • Developers who use SQL written by an LLM (chatbot or coding assistant) on production or analytics databases

  • Data analysts and planners who use figures generated by LLMs in their materials

  • Team leaders and DBAs who need to review SQL written by an LLM teammate

Curriculum (5 sections · 7 lessons · approximately 58 minutes)

  • Section 1. Scene 1 — Inflated Revenue — Inflated Revenue — Joins multiply the totals

  • Section 2. Scene 2 — The Entire Database Was Read — The Entire Database Was Read ① Conditions That Bypass Indexes, The Entire Database Was Read ② No Row Limit and a Large Sort

  • Section 3. Scene 3 — Leaked Personal Information — Leaked Personal Information

  • Section 4. Scene 4 — Mismatched Active Members — Mismatched Active Members ① NULL and NOT IN, Mismatched Active Members ② Boundary Dates and Time Zones

  • Section 5. Scene 5 — The Most Dangerous One Is the One That Passes — The Most Dangerous One Is the One That Passes — Review Verdict Table

Practice Environment

Launch MySQL 8.4 in Docker on your laptop, and create data for the virtual shopping mall 'Gureum Yeonpil'—20,000 members, 100,000 orders, about 220,000 order details, about 110,000 payments, and 300,000 access records—with a single command. The data is generated using fixed rules, so no matter who runs it, the row counts, totals, and rows read will match those shown in the course (only the runtime and EXPLAIN’s estimated row counts may vary slightly). Lesson 1 includes the complete hands-on practice ZIP (llmsql-lab.zip: 00_Sijak_annae.pdf at the top level, seven lesson-specific practice guide PDFs, lesson-specific one-click run files L01~L07_BaroSilhaeng.sh, the original SQL files, the verification checklist PDF, and the original commands used during recording). Lessons 2–7 include a practice kit containing only that lesson (llmsql-L02~L07.zip: practice guide PDF + one-click run file + practice database). The practice guide PDFs include the expected numbers, actual execution screens, common sticking points, review questions and answers, and a checklist.

Prerequisites

  • SQL skills sufficient to read SELECT, JOIN, and GROUP BY

  • A computer on which Docker can be installed (hands-on practice is optional)

What This Course Does Not Cover

  • Those who want to learn how to use a specific LLM product or prompt engineering techniques.

  • Those looking to learn in-depth execution plan analysis and query tuning

  • Those who want to learn SQL syntax from scratch (we recommend taking an introductory course first)

Notice

The video was made using slides and synthesized speech (TTS), and the script was written with the help of AI tools. The numbers and results shown on screen, along with the terminal display, are all from actual executions and their screenshots. The 'SQL generated by the LLM' in the video is an example reconstructed to reflect the kinds of queries LLMs commonly produce. All data is fictional and for educational purposes; numbers may vary depending on the execution environment.

Recommended for
these people

Who is this course right for?

  • Developers who use LLMs (chatbots and coding assistants) to write SQL and run it against production or analytics databases.

  • Data analysts and planners who use figures generated by LLMs in their reports

  • Leaders and DBAs who need to review SQL generated by team members using LLMs

Need to know before starting?

  • SQL at a level sufficient to read SELECT, JOIN, and GROUP BY statements

  • A computer that can run Docker (the exercise is optional)

Hello
This is dorian05202988

Career Verified

161

Learners

3

Reviews

2.3

Rating

47

Courses

A data craftsman with over 20 years of experience in databases and IT. As a DBA and manager of a DB Platform team, I work with database platforms and specialize in MySQL, PostgreSQL, Oracle, MongoDB, SQL tuning, AWS, Terraform, and Python. Drawing on experience in the gaming, finance, and IT services industries, I explain database and cloud architecture. I have published 『Oracle Practical Tuning: Learning SQL Patterns』 and 『Oracle Pro*C Practical Project Guide』, and have presented on serverless architectures, database selection, and multi-database strategies at AWS Summit 2018 and 2019 and DataYa Nolja 2020. Recently, I have been working on slow-query analysis and tuning recommendations using Bedrock LLM, automated DB specification sizing, and query workflows through a DB metadata MCP server and Slack bot. I explain database automation for developers and AI applications for non-developers through hands-on exercises tailored to the audience and objectives of each course. Rather than applying AI suggestions as-is, I teach a decision-making framework that verifies result equivalence, execution plans, and observability conditions, and defers action when the supporting evidence is insufficient. Company operational data and credentials are not included in the course materials.

More

Curriculum

All

7 lectures ∙ (57min)

Course Materials:

Lecture resources
Published: 
Last updated: 

Reviews

Not enough reviews.
Please write a valuable review that helps everyone!

dorian05202988's other courses

Check out other courses by the instructor!

Similar courses

Explore other courses in the same field!

Free