0Pricing
Prompt Engineering & LLM Optimization for Developers · 강의

자연어로 SQL 질의 생성

스키마 맥락, 예시, 안전장치를 제공해 LLM이 일상적인 영어 질문을 올바른 SQL로 변환하도록 프롬프트를 작성하는 방법을 배웁니다.

자연어로 SQL 질의 생성은(는) CoddyKit의 무료 Prompt Engineering & LLM Optimization for Developers 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Prompt Engineering & LLM Optimization for Developers 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Prompt Engineering & LLM Optimization for Developers 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Text-to-SQL Overview

One of the most practical developer uses of LLMs is turning a plain question like How many orders shipped last week? into a runnable SQL query.

Done well, it lets non-experts query data and speeds up everyday analysis.

The Model Needs the Schema

An LLM cannot guess your table and column names. Always include the relevant schema in the prompt so it references real fields.

Schema:
orders(id, customer_id, status, total, created_at)
customers(id, name, country)

A Basic Text-to-SQL Prompt

Combine schema, the question, and an instruction to return only SQL.

Given the schema above, write a single
Postgres query. Return only SQL.
Question: total revenue per country last month.

Specify the Dialect

SQL dialects differ (Postgres, MySQL, SQLite, BigQuery). State which one you use, or the model may emit functions your database does not support.

Few-Shot Examples Help

Showing one or two question-to-SQL pairs teaches the model your conventions, like how you format dates or name aliases.

Q: customers from Japan
SQL: SELECT * FROM customers WHERE country = 'Japan';
Q: orders over 100
SQL: SELECT * FROM orders WHERE total > 100;

Handling Joins

For questions spanning tables, hint at the relationships in the schema (foreign keys) so the model joins correctly instead of guessing.

-- orders.customer_id references customers.id
SELECT c.country, SUM(o.total)
FROM orders o JOIN customers c
  ON o.customer_id = c.id
GROUP BY c.country;

Guardrail: Read-Only

Never run model-generated SQL with write access. Restrict the connection to SELECT only and reject any query containing DELETE, UPDATE, or DROP.

if (/\b(delete|update|drop|insert)\b/i.test(sql)) {
  throw new Error('Only read queries allowed');
}

Validate Before Executing

Parse or EXPLAIN the query before running it. This catches syntax errors and lets you reject queries touching tables outside an allowlist.

EXPLAIN SELECT ...; -- check plan, no data fetched

Self-Correction Loop

If the query errors, feed the database error message back to the model and ask it to fix the SQL. Two or three attempts usually resolve most mistakes.

The query failed with: column "revenue"
does not exist. Fix the SQL.

Explaining Results

After running the query, you can ask the model to summarize the rows in plain language, closing the loop from question to readable answer.

Limits to Remember

  • Ambiguous questions yield ambiguous SQL.
  • Large schemas may not fit in context, retrieve the relevant tables.
  • Always verify aggregates on critical reports.

Quick Check

Test your understanding of text-to-SQL.

Recap

Text-to-SQL works by giving the model the schema, dialect, and few-shot examples, then validating output. Always run generated SQL read-only, validate before executing, and use a self-correction loop on errors.

자주 묻는 질문

“자연어로 SQL 질의 생성” 강의는 무료인가요?

네 — “자연어로 SQL 질의 생성” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Prompt Engineering & LLM Optimization for Developers 강의 전체를 잠금 해제할 수 있습니다. Prompt Engineering & LLM Optimization for Developers 강의에는 총 4개의 강의가 포함되어 있습니다.

“자연어로 SQL 질의 생성”에서 뭘 배우나요?

스키마 맥락, 예시, 안전장치를 제공해 LLM이 일상적인 영어 질문을 올바른 SQL로 변환하도록 프롬프트를 작성하는 방법을 배웁니다. 브라우저에서 직접 실행하는 실습 코드로 Prompt Engineering & LLM Optimization for Developers을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Prompt Engineering & LLM Optimization for Developers을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Prompt Engineering & LLM Optimization for Developers은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“자연어로 SQL 질의 생성” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Prompt Engineering & LLM Optimization for Developers 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Prompt Engineering & LLM Optimization for Developers 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 코드 생성 및 리팩터링
  2. 디버깅 및 테스트 사례 생성
  3. 데이터 추출 및 요약
  4. 자연어로 SQL 질의 생성
← Prompt Engineering & LLM Optimization for Developers(으)로 돌아가기