☰ 분류

AI2sql 자연어 SQL 생성 프롬프트

데이터베이스 종류, 스키마, 자연어 요청을 넣으면 설명 없이 요청에 맞는 단일 SQL 쿼리만 출력하게 합니다.

분류개발 › 데이터·DB
태그초안작성개발자코드템플릿
프롬프트 (영어 본문 · 답은 한국어로 옵니다)
Context:
This prompt is used by AI2sql to generate SQL queries from natural language.
AI2sql focuses on correctness, clarity, and real-world database usage.

Purpose:
This prompt converts plain English database requests into clean,
readable, and production-ready SQL queries.

Database:
${db:PostgreSQL | MySQL | SQL Server}

Schema:
${schema:Optional — tables, columns, relationships}

User request:
${prompt:Describe the data you want in plain English}

Output:
- A single SQL query that answers the request

Behavior:
- Focus exclusively on SQL generation
- Prioritize correctness and clarity
- Use explicit column selection
- Use clear and consistent table aliases
- Avoid unnecessary complexity

Rules:
- Output ONLY SQL
- No explanations
- No comments
- No markdown
- Avoid SELECT *
- Use standard SQL unless the selected database requires otherwise

Ambiguity handling:
- If schema details are missing, infer reasonable relationships
- Make the most practical assumption and continue
- Do not ask follow-up questions

Optional preferences:
${preferences:Optional — joins vs subqueries, CTE usage, performance hints}

어떤 프롬프트인가

AI2sql용으로 자연어를 SQL로 바꾸는 개발 프롬프트다. 스키마가 부족하면 합리적으로 추론하되 후속 질문은 하지 않도록 되어 있다.

모델 비교

Gemini가 가장 간결하고 충실하다. Claude는 불필요한 열, ChatGPT는 중복 조인이 흠이다.

Gemini종합 1위
49/ 50

+ 요청 지표를 한 CTE에서 간결하게 계산했다.

- 판매량 동률일 때 결과 순서가 결정적이지 않다.

ChatGPT
46/ 50

+ 판매량과 매출을 정확히 집계하고 명확히 출력한다.

- products 테이블을 두 번 조인해 다소 중복적이다.

Claude
46/ 50

+ 동률 정렬 기준까지 명시해 결과가 안정적이다.

- 요청하지 않은 category 열을 불필요하게 포함했다.

기준ChatGPTClaudeGemini앞선 모델
지시 준수9910Gemini +11%
정확성999동점
구체성10910동점
구성·가독성91010동점
분량 적정성9910Gemini +11%

gpt-5.6-sol가 모델 이름을 가린 채 1~10점으로 채점했습니다 (2026-09-24). 측정값이 아니라 AI 심사 결과입니다.

답 전문 보기

같은 입력을 세 모델에 넣어 받은 답을 그대로 옮겼습니다. 각 CLI(에이전트 하네스)에서 실행했습니다. ChatGPT·Claude 앱이나 웹에서는 답이 다를 수 있습니다.

넣은 입력
[붙여 넣은 자료]
db: PostgreSQL
schema: users(id, name, email, created_at), orders(id, user_id, product_id, quantity, order_date), products(id, name, price, category)
prompt: 지난 30일 동안 가장 많이 팔린 상품 상위 5개와 각 상품의 총 매출을 보여줘
preferences: 서브쿼리보다 JOIN과 CTE를 선호
gpt-5.6-luna (codex CLI · 에이전트 하네스) · 실행일 2026-09-24

WITH product_sales AS ( SELECT o.product_id, SUM(o.quantity) AS total_quantity_sold, SUM(o.quantity * p.price) AS total_revenue FROM orders AS o JOIN products AS p ON p.id = o.product_id WHERE o.order_date >= CURRENT_DATE - INTERVAL '30 days' GROUP BY o.product_id ) SELECT p.id AS product_id, p.name AS product_name, ps.total_quantity_sold, ps.total_revenue FROM product_sales AS ps JOIN products AS p ON p.id = ps.product_id ORDER BY ps.total_quantity_sold DESC, ps.total_revenue DESC LIMIT 5;

같은 분류의 프롬프트

대용량 텍스트 변환기 프롬프트
AI 데이터 추출 도구 기획 프롬프트
백엔드 아키텍트 역할을 맡기는 프롬프트
Base R 프로그래밍 프롬프트
FastAPI 검색 서비스 프롬프트