In this exercise you will practice
You work for the registrar of a major university and have been tasked with creating a database to hold courses and semester schedules.
Write a SQL script named registration-schema.sql
that creates a database with the following tables:
student(student_id, name, gpa)
dept(dept_id, name, dean, building, room)
course(dept_id, course_id, name, hours), where dept_id is a foreign key referencing the dept(dept_id)
enrolled(dept_id, course_id, student_id), where (dept_id, course_id) is a foreign key referencing course(dept_id, course_id) and student_id is a foreign key referencing student(student_id)
Write a SQL script that populates the following data:
student_id | name | gpa |
---|---|---|
11 | Bush | 3.0 |
12 | Cruz | 3.2 |
13 | Clinton | 3.9 |
22 | Sanders | 3.0 |
33 | Trump | 3.8 |
dept_id | coruse_id | student_id |
---|---|---|
CS | 101 | 11 |
Math | 101 | 11 |
CS | 101 | 12 |
CS | 201 | 22 |
Math | 201 | 33 |
EE | 102 | 33 |
Math | 301 | 22 |
dept_id | name | dean | building | room |
---|---|---|---|---|
CS | Computer Science | Rubio | Ajax | 100 |
Math | Mathemagics | Carson | Acme | 300 |
EE | Electrical Engineering | Kasich | Ajax | 200 |
IE | Industrial Engineering | Cruz | 200 | |
Music | Musicology | Costello | North | 100 |
dept_id | course_id | name | hours |
---|---|---|---|
CS | 101 | Programming | 4 |
CS | 201 | Algorithms | 3 |
CS | 202 | Systems | 3 |
Math | 101 | Algebra | 3 |
Math | 201 | Calculus | 4 |
Math | 301 | Analysis | 4 |
Music | 104 | Jazz | 3 |
EE | 102 | Circuits | 3 |
IE | 101 | Proabability | 3 |
IE | 102 | Statistics | 3 |
Once the database has been populated, make the following updates:
Write a sql script with queries that answer the following questions.
Easy Queries:
Intermediate queries
Don’t peek until you’ve tried the exercise on your own!