Automated Grading of SQL Exercises Using SQLite
A new method for grading SQL exercises involves running student queries against a real SQLite database and comparing the results directly, ensuring accuracy and fairness in assessment.

Automated grading of SQL exercises can be achieved by running student queries against a real SQLite database and comparing the output rows. This method avoids the limitations of comparing query syntax, as different correct queries can yield the same results. The grading process involves sending the student’s query to a sandboxed code execution API, such as OnlineCompiler.io, where it runs against a preloaded database file. The API executes the query, compares the output rows to expected results, and returns a verdict for each test case. This ensures that the grading is based on the correctness of the results, not the structure of the query. [1]
The grading system uses a predefined set of tests to evaluate the correctness of a student's query. Each test includes an input value, such as a threshold for total loan days, and the expected output. For example, if the input is 30, the expected output is 'ada|35'. The system runs the query against the database for each test, compares the output rows, and checks if they match the expected results. The comparison is done as an unordered set of rows, meaning that the order of the output does not affect the result. This is important because different queries may return rows in varying orders, and the grading should not penalize students for this. [1]
Several common issues can arise during grading, such as queries that use incorrect operators (e.g., '>' instead of '>='), queries that omit necessary filters, or queries that hard-code answers. These issues can be detected by including test cases that check for boundary conditions, such as values that are exactly equal to the threshold. For example, a test with an input of 23 can catch a query that mistakenly uses '>' instead of '>='. The grading system also handles cases where students attempt to modify the database, such as using 'DELETE FROM loans', by running the query in a read-only environment, which prevents such actions and ensures data integrity. [1]
Automated grading of SQL exercises can be achieved by running student queries against a real SQLite database and comparing the output rows. This method ensures that queries are evaluated based on their actual results rather than their syntax alone. The grading system uses a predefined set of tests to evaluate the correctness of a student's query (Dev.to, 2023). [1]
Advertisement
A small library database example demonstrates how this grading system works. The database includes tables with member, book, and days data, and the grading system tests queries that compute the total days borrowed by each member. The system runs each query in a sandbox environment to ensure safety (Dev.to, 2023). [1]
The grading system sends each query to a code execution API that runs it in a sandbox with no network access. The system uses a Python script to send the query, database file, and tests to the API, which returns a verdict for each test. This approach allows for accurate evaluation of student queries (Dev.to, 2023). [1]
Automated grading of SQL exercises can be achieved by running student queries against a real SQLite database and comparing the output rows. This approach allows for the evaluation of correctness based on results rather than syntax or structure. The grading system uses a predefined set of tests to evaluate the correctness of a student's query, ensuring that different correct queries are accepted regardless of their formulation. For example, three different queries that answer the same question are accepted by the grader (Dev.to, 2023). [1]
A small library database example demonstrates how the grading system works. The database contains information about members, books, and the number of days each member borrowed a book. The grading system sends each query to a code execution API that runs it in a sandbox with no network access. This ensures that the student's query is executed in a secure environment, preventing any unintended modifications to the database (Dev.to, 2023). [1]
Advertisement
The grading system uses a set of predefined tests to check the output of each query. Each test provides an input value, such as the number of days (N), and the expected output. For instance, when N is 30, the expected output is only 'ada|35', while when N is 20, the expected output includes both 'ada|35' and 'bob|23'. This method ensures that queries are evaluated based on the accuracy of their results (Dev.to, 2023). [1]
Sources
Prepared with AI assistance from the cited sources.
The Cali Reporter newsletter
The stories worth your time.
California, the country, and what comes next. Join our free newsletter for reporting that keeps you informed.
More in Technology
- Modern Web Guidance 1.0 and Browser Compatibility
Modern Web Guidance 1.0, announced by Chrome for Developers on November 10, introduces browser compatibility data to assist coding agents in building web features. The initiative emphasizes the importance of fallback…
- Apache mod_http2 Vulnerability Detection with Nmap
A new Nmap scripting module has been developed to detect the Apache mod_http2 vulnerability (CVE-2026-119618), addressing the challenges of identifying affected systems accurately.
- Securing Remote Vendor Access in Industrial Networks
Best practices for managing remote vendor access in operational technology (OT) networks emphasize controlled access points, multifactor authentication, and time-bound sessions to reduce cybersecurity risks.
