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.

75
Duration
12s
Input Tokens
1029
Output Tokens
586
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
-- First, add the course_id column to completions (if not already present)
-- ALTER TABLE completions ADD COLUMN course_id INT;

-- Update the course_id column based on the lesson's course_id
-- UPDATE completions c
-- SET course_id = l.course_id
-- FROM lessons l
-- WHERE c.lesson_id = l.lesson_id;

-- Add the composite foreign key constraint
ALTER TABLE completions
ADD CONSTRAINT fk_completions_enrollments
FOREIGN KEY (user_id, course_id) REFERENCES enrollments(user_id, course_id);