CS Grade 9-12

CS: Databases and SQL Basics

Understanding tables, queries, keys, and simple SQL commands

View Answer Key
Name:
Date:
Score: / 12

Understanding tables, queries, keys, and simple SQL commands

CS - Grade 9-12

Instructions: Read each problem carefully. Use complete SQL statements when asked to write a query. Show your work in the space provided.
  1. 1
    A database table grid with one row and one column highlighted.

    In a relational database, data is often stored in tables. Explain what a table, row, and column represent.

  2. 2

    A Students table has these columns: student_id, first_name, last_name, grade_level. Write a SQL query that selects all columns from the Students table.

  3. 3

    A Books table has these columns: book_id, title, author, year_published. Write a SQL query that shows only the title and author of every book.

  4. 4

    A Products table has these columns: product_id, name, category, price. Write a SQL query that selects all products with a price greater than 25.

  5. 5

    A Movies table has these columns: movie_id, title, rating, release_year. Write a SQL query that selects movie titles released in 2020 or later, sorted from newest to oldest.

  6. 6

    A Customers table has these columns: customer_id, first_name, last_name, email. Identify the best primary key and explain why it is a good choice.

  7. 7

    A Classes table has these columns: class_id, class_name, teacher_name. Write a SQL INSERT statement that adds a class with class_id 12, class_name 'Biology', and teacher_name 'Ms. Patel'.

  8. 8

    An Employees table has these columns: employee_id, name, department, hourly_rate. Write a SQL UPDATE statement that changes the hourly_rate to 18.50 for the employee with employee_id 7.

  9. 9

    A table named Pets has these rows: (1, 'Milo', 'cat'), (2, 'Bella', 'dog'), (3, 'Luna', 'cat'). The columns are pet_id, pet_name, species. What rows are returned by SELECT pet_name FROM Pets WHERE species = 'cat';?

  10. 10
    Two database tables connected by matching highlighted columns.

    Two tables are shown. Students has student_id and student_name. Enrollments has enrollment_id, student_id, course_name. Explain how student_id can be used to connect these tables.

  11. 11
    Two related database tables joined into one result table.

    Using Students(student_id, student_name) and Enrollments(enrollment_id, student_id, course_name), write a SQL query that lists each student_name with the course_name they are enrolled in.

  12. 12

    A database designer stores a customer's full address in one column named full_address. Explain one reason it might be better to separate the address into columns such as street, city, state, and zip_code.

LivePhysics™.com CS - Grade 9-12

More CS Worksheets

See all CS worksheets

More Grade 9-12 Worksheets

See all Grade 9-12 worksheets