Bonus: AI + SQL Cheat Sheet

What's in this cheat sheet

This cheat sheet goes with my YouTube video on 7 ways developers use AI with their database. In it, you'll find:

  • The one rule to follow before you paste anything into an AI tool
  • The 7 ways to use AI with your database
  • An example prompt for each way, ready to copy

The prompts work in GitHub Copilot Chat, Claude, ChatGPT, Microsoft Copilot or the AI assistant in your SQL editor. Swap the parts in [brackets] for your own details.

Prefer a PDF? You can download the PDF version of this cheat sheet.

The Rule: Share the Structure, Not the Data

Check your company's AI policy first. It covers which tool you can use and also what you're allowed to put into it.

Don't share: real customer data, passwords and connection strings, or proprietary code and schema details unless your tool is approved for it.

Share instead: table and column definitions, fake sample rows, and execution plans with the real names swapped for generic ones.

1. Explain a Query or Schema You Didn't Write

1Explain this [PostgreSQL] query step by step in plain English. Tell me what each part does and what the final result will contain.
2
3[paste your query]

Asking what the result will contain makes the AI describe the output, not just the syntax. You can do the same with a CREATE TABLE script for a database you've just joined.

2. Draft a Query From Plain English

1Here are my table definitions:
2[paste your CREATE TABLE statements]
3
4Write a [PostgreSQL] query that [shows each customer's name and their total spend in the last 90 days, only for customers with more than 3 orders in that period].

Give it your schema first, or it will invent table and column names. Treat the result as a first draft and test it on a small data set before you trust it.

3. Review and Tune a Slow Query

1Here is a slow [PostgreSQL] query and its execution plan. Explain where the time is going and suggest changes to make it faster.
2
3[paste your query]
4[paste your execution plan]

Swap your real table and column names for generic ones, such as table_a and table_b, before you share the plan. Then try the suggestion, run the plan again and compare the two.

4. Debug an Error Message

1Here's my query and the error. Explain why this error happens, then show me the fixed query.
2
3[paste your query]
4[paste the error message]

Ask why, not just how to fix it. If you understand the reason, you won't be back next week with the same error.

5. Generate Test and Sample Data

1Here are my table definitions. Write INSERT statements for [5 customers and about 15 orders] of realistic fake data. I'm testing a query that [finds customers with more than 3 orders in the last 90 days]. Use CURRENT_DATE so the dates stay relative to today. Include [a customer with a NULL email, two customers with the same name, a customer with exactly 3 orders, an order exactly 90 days ago, an order 91 days ago, and an order with a total of 0].
2
3[paste your CREATE TABLE statements]

Tell it what you're testing and name the edge cases you want, because that's where queries fail on real data. You can also paste in the acceptance criteria from a user story.

6. Translate SQL Between Databases

1Convert this [Oracle] query to [PostgreSQL]. Then list every change you made and explain why each one was needed.
2
3[paste your query]

Run both versions and compare the results. Date handling and vendor-specific functions are where AI tools are most likely to slip.

7. Document Your Database

1Here are my table definitions. Write a one-sentence description of each table and each column, in plain English, for a new team member. Write them as [PostgreSQL] COMMENT ON statements.
2
3[paste your CREATE TABLE statements]

The AI only knows what you show it, so it will guess things like whether a total includes tax or what a status of 1, 2 or 3 means. Correct those before you run the statements.

Want to design a database from scratch?

Design Any Database in 60 Minutes is a 7-step framework that takes you from a real-world requirement to a working schema. You can get it here: Design Any Database.