SQL Generation

Turn plain-English questions into correct SQL against a schema. The skill behind analytics chat, natural-language dashboards, and 'just ask the database' interfaces.

75
Duration
4s
Input Tokens
1031
Output Tokens
711
Cost
$0.00
Context
Input
Add a foreign key from completions to enrollments, linking through user_id and course_id to ensure data consistency.
Expected output
ALTER TABLE completions ADD COLUMN course_id INT, ADD CONSTRAINT fk_completions_user_course FOREIGN KEY (user_id, course_id) REFERENCES enrollments(user_id, course_id);
Model output
ALTER TABLE completions ADD COLUMN course_id INT;

ALTER TABLE completions ADD CONSTRAINT fk_completions_enrollments
FOREIGN KEY (user_id, course_id) REFERENCES enrollments(user_id, course_id);

ALTER TABLE completions ADD CONSTRAINT fk_completions_lessons
FOREIGN KEY (lesson_id, course_id) REFERENCES lessons(lesson_id, course_id);