SQL

Natural language to SQL query generation evaluates text-to-query fidelity and schema reasoning. This task is particularly relevant for analytics chat assistants and simplified database interfaces where users need to query data using natural language. Models must understand both the intent behind the question and the structure of the underlying database schema.

100
Duration
49s
Input Tokens
972
Output Tokens
2531
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
BEGIN;
ALTER TABLE completions ADD COLUMN course_id INT;
UPDATE completions c
SET course_id = l.course_id
FROM lessons l
WHERE l.lesson_id = c.lesson_id;
ALTER TABLE completions ALTER COLUMN course_id SET NOT NULL;
ALTER TABLE completions
ADD CONSTRAINT completions_enrollment_fk
FOREIGN KEY (user_id, course_id)
REFERENCES enrollments (user_id, course_id);
COMMIT;