Step-by-step
🗄️ GitHub Copilot
GitHub
📘 Step-by-step 📘 GitHub · GitHub Copilot↗ GitHub Copilot · Official sitebeginner 💼 Business

Generate SQL queries by describing what you want in plain English

Use GitHub Copilot Chat to draft SELECT, UPDATE, and COUNT statements from plain-English questions, then verify the result against a real row.

In short: GitHub Copilot Chat can turn a plain-English question like "show me last week's top customers" into a working SQL query. You still need to read the result and test it against a real row before you trust it.

You've stared at a SQL query before, wondering what it actually does. Or maybe you've wanted a query but didn't want to spend an hour Googling the right JOIN. Either way, you can describe what you want in plain English and let GitHub Copilot Chat write a first draft for you. This guide walks you through the loop: ask, read, run, verify. You don't need to know SQL well — you just need a real question about real data.

💡 Tip: tap a step’s number when you finish it — a green tick appears and your browser remembers how far you got.

✅ Before you start
  • An active GitHub Copilot subscription (free trials are sometimes available; check GitHub's current pricing page for what your account qualifies for).
  • A code editor with Copilot Chat installed — VS Code is the most common starting point — or a github.com account that has access to Copilot Chat in the browser.
  • A database you can connect to (Postgres, MySQL, Snowflake, BigQuery, SQLite — anything works) and a tool that lets you run SQL against it.
  • One table you want to query, plus a rough idea of what columns it has (the names, not the SQL).
  • Roughly 10–15 minutes for your first end-to-end try.
1

Open Copilot Chat

Open your code editor (such as VS Code) and look for the Copilot icon — it usually looks like a small chat bubble or a sparkle, often in the title bar at the top of the window or in the activity bar on the left. Click it to open the Copilot Chat panel. A side window opens with an empty text box and placeholder text like "Ask Copilot…" or "Type a message…". If you don't see the icon, open your editor's command menu (usually Ctrl+Shift+P on Windows/Linux or Cmd+Shift+P on Mac) and search for "Copilot Chat" — selecting it from the list opens the same panel. On github.com, look for the Copilot icon in the top navigation bar instead. You'll know it worked when a chat input box appears with your name or avatar at the top of the conversation.

2

Tell Copilot about your tables

Before asking for a query, give Copilot the shape of the data it should write against. The fastest way is to open a SQL file that contains your CREATE TABLE statements (the lines that describe each column and its type) and mention the file in your prompt. If you don't have such a file, paste a short description of the table directly into the chat. Copilot uses this to write the right table and column names instead of inventing plausible-looking ones that don't exist in your database. 💬 Example: "I'm working with a table called orders that has columns id (integer), customer_id (integer), order_date (date), total_amount (decimal), and status (text)." You'll know it worked when Copilot's next SQL statement uses those exact column names — not invented ones like order_total or cust_id.

3

Ask your question in plain English

In the chat box, write the question the way you'd ask a colleague. Be specific about time ranges, filters, sort order, and how many rows you want. One or two sentences is usually enough; long, vague prompts tend to confuse the model. Copilot will respond with a code block containing a SQL statement — usually a SELECT, sometimes a COUNT or an UPDATE, depending on what you asked for. 💬 Example: "Show me the top 5 customers by total order amount in the last 30 days, sorted from highest to lowest. Include the customer email and total spent." If you don't get a code block, or the query doesn't match what you wanted, add one more detail and ask again rather than rewriting from scratch. You'll know it worked when a SQL query appears in a code block that mentions your real table and real column names.

4

Read the SQL before you run it

Treat Copilot's output like a first draft from a junior colleague — useful, but worth a careful look. Read the FROM, WHERE, GROUP BY, ORDER BY, and LIMIT lines in order, and ask yourself: which rows does this keep, and which does it throw away? For UPDATE or DELETE queries especially, check that a WHERE clause exists and is correct — an UPDATE without a WHERE will rewrite every row in the table. If any clause looks unfamiliar, ask Copilot to explain it in plain English before you run anything. 💬 Example: "Explain in one sentence what the WHERE clause in your last query is filtering for." You'll know it worked when you can describe, out loud, what the query returns and which rows it leaves out.

5

Run the query against your database

Copy the SQL from the chat and paste it into the tool you normally use to talk to your database — that might be the SQL editor in your cloud dashboard, a desktop client like DBeaver or TablePlus, or a notebook connected to your warehouse. Click run. Two things can happen: you get rows back, or you get an error message. If you get an error, paste the exact error text back into Copilot Chat and ask it to fix the query — the most common errors are typos in column names, missing quotation marks around strings, or date formats your database doesn't accept. You'll know it worked when you see a result table with the columns you asked for and roughly the number of rows you expected (a "top 5" should return 5 rows, for example).

6

Verify with a sample row and ask for fixes if needed

Even when a query runs without error, the rows might still be subtly wrong — dates off by a time zone, totals missing tax, joins silently multiplying rows. Pick one row from the result and check it manually against the source data or a report you already trust. If everything matches, you're done. If something is off, tell Copilot what you expected versus what you got, and ask it to adjust. 💬 Example: "The query returned 1,243 rows but I know we had 2,500 orders in the last 30 days. The date filter is probably excluding orders placed on the first day. Can you check?" You'll know it worked when a row you can verify by hand matches what the query returned, and the totals make sense in plain language — not just in SQL.

⚠️ Common mistakes
  • Trusting the result without checking. Copilot can write plausible-looking SQL that's subtly wrong (a wrong join, wrong date math, a missing filter). Always pick one row and verify it against the source.
  • Skipping the schema step. Without your real table and column names, Copilot will invent names that look right but don't exist — and you'll get a "column not found" error at best, wrong data at worst. Paste the schema first.
  • Running UPDATE or DELETE straight from the chat. An UPDATE without a WHERE clause rewrites every row. Run the same logic as a SELECT first, check the rows it returns, and only then change SELECT to UPDATE.
🚀 Try it now

Open your database tool, paste your table's column names into Copilot Chat, and ask: "How many rows does the [your table name] table have?" Run the resulting query and see if the number matches what you already know. Two minutes, real result.

❓ Quick questions

How long does this take?

About 6 minutes — the guide has 6 steps, and you can tick each one off as you go.

Which tool do I need?

This guide uses GitHub GitHub Copilot — but the approach works very similarly in other AI assistants.

Do I need to prepare anything?
  • An active GitHub Copilot subscription (free trials are sometimes available; check GitHub's current pricing page for what your account qualifies for).
  • A code editor with Copilot Chat installed — VS Code is the most common starting point — or a github.com account that has access to Copilot Chat in the browser.
  • A database you can connect to (Postgres, MySQL, Snowflake, BigQuery, SQLite — anything works) and a tool that lets you run SQL against it.
  • One table you want to query, plus a rough idea of what columns it has (the names, not the SQL).
  • Roughly 10–15 minutes for your first end-to-end try.
What mistakes should I avoid?
  • Trusting the result without checking. Copilot can write plausible-looking SQL that's subtly wrong (a wrong join, wrong date math, a missing filter). Always pick one row and verify it against the source.
  • Skipping the schema step. Without your real table and column names, Copilot will invent names that look right but don't exist — and you'll get a "column not found" error at best, wrong data at worst. Paste the schema first.
  • Running UPDATE or DELETE straight from the chat. An UPDATE without a WHERE clause rewrites every row. Run the same logic as a SELECT first, check the rows it returns, and only then change SELECT to UPDATE.

Keep reading

Was this helpful?

✦ Original step-by-step guide by AI World HQ's AI editorial team. Written in plain language, reviewed for accuracy.

← Back to all stories