Creating a SQL Exercise

How to create a SQL activity using CodeHS Create

Sara Jenis avatar
Written by Sara Jenis
Updated over a week ago
Banner: Free feature

You can make you own autograded SQL problems in CodeHS Create. There are only a few steps to writing a good SQL program, and you can see a demo in the video below!

Create an assignment from Create page or Assignments page

Step 1: Create a SQL Exercise

  • Click Create New Assignment from your Create or Assignments page

  • Choose Coding Exercise > Select a SQL Program Type

  • Fill in assignment details: title, description, and starter code

Step 2: Add Data and Solution Code through Advanced Settings

  • Click the three dots > edit next to your assignment

  • Click on Advanced Settings (bottom left)

  • Click the SQL Setup Code Tab

  • Add your data. Note: Make sure to add the Table Names into SQL Tables

  • Click on the Code Tab

  • Enter your Starter Code and Solution Code

SQL Setup Code

You can use this sample code to help create tables and add data:


CREATE TABLE Name (id, first_name, last_name, house);
INSERT into Name values ("1", "Harry", "Potter", "1");
INSERT into Name values ("2", "Ron", "Weasley", "1");
INSERT into Name values ("3", "Hermione", "Granger", "1");
INSERT into Name values ("4", "Severus", "Snape", "4");



CREATE TABLE House (house_name, house_id);
INSERT into House values ("Gryffindor", "1");
INSERT into House values ("Ravenclaw", "2");
INSERT into House values ("Hufflepuff", "3");
INSERT into House values ("Slytherin", "4");

Create an assignment in a Playlist

  1. Start by creating a playlist, and make a new activity. Choose SQL for the problem type.

  2. Write a description describing what your students should query.

  3. Load in Data in the SQL Setup Code tab by writing queries that generate a Database with your content.

  4. Write the correct query in the Solution Code section of the Code tab.

  5. Assign to your students! They'll be able to load the problem, start with the preloaded data, and write queries. The autograder will automatically check if their results match what your solution code produces.

Still have questions? Contact our team at hello@codehs.com to learn more!

Did this answer your question?