Practice core database ideas and write basic SQL queries using SELECT, WHERE, ORDER BY, INSERT, UPDATE, and simple joins.
Read each problem carefully. Use complete SQL statements when asked to write a query. Show your work in the space provided.
Understanding tables, queries, keys, and simple SQL commands
CS - Grade 9-12
- 1
In a relational database, data is often stored in tables. Explain what a table, row, and column represent.
- 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
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
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
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
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
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
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
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
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
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
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.