You are on page 1of 3

SQL: Assignment 3

To study something you have to practice more than usual.

Part 1: CREATE Command

1. Students Table
• Create a table named Students.
• This table should have columns for:
• A student ID as the primary key
• First name
• Last name
• Birthdate
• Class (e.g., 10A, 10B, etc.)
2. Teachers Table
• Create a table named Teachers.
• This table should have columns for:
• A teacher ID as the primary key
• First name
• Last name
• Subject they teach
3. Subjects Table
• Create a table named Subjects.
• This table should have columns for:
• A subject ID as the primary key
• Subject name
• Associated teacher ID (as a foreign key)
4. Classrooms Table
• Create a table named Classrooms.
• This table should have columns for:
• A classroom ID as the primary key
• Room number
• Capacity (number of students)
5. Enrollments Table
• Create a table named Enrollments.
• This table should link students to subjects.
• It should have columns for:
• An enrollment ID as the primary key
• Student ID (as a foreign key)
• Subject ID (as a foreign key)

Page 1 of 3
SQL: Assignment 3

Part 2: ALTER Command

Alter your existing table structures as per the following requirements:

1. Update Students Table


• Add an Email column to the Students table to store their email addresses.
• Modify the Class column in the Students table to allow it to store longer
class names (e.g., changing its type to allow more characters).
2. Update Teachers Table
• Add a PhoneNumber column to the Teachers table to store the contact
number of the teachers.
• Add a new column called HireDate to store the date on which the teacher
was hired. It should store date values.
3. Update Subjects Table
• Rename the SubjectName column to just Name. This simplifies the naming but
still remains understandable in the context of the table.
4. Update Classrooms Table
• Add a new column called Floor to specify on which floor the classroom is
located. It should be an integer type.
5. Bonus:
• Drop the Capacity column from the Classrooms table. (Note: Dropping a
column is a destructive operation and data will be lost. Always make sure
to backup data before such operations.)

Part 3: INSERT Command

• Insert sample data into the tables you've created:


1. Insert at least 5 records (student information) into the Students table.
2. Insert some teachers into the Teachers table.
3. Insert subjects into the Subjects table and associate them with the teachers
you added.
4. Insert a few classrooms into the Classrooms table.
5. Enroll the students you added in some of the subjects using the
Enrollments table.

Page 2 of 3
SQL: Assignment 3

Part 4: SELECT Command

Using the SELECT statement, retrieve the following data sets:

1. All Students' Information


• Write a query to select all columns from the Students table.
2. Specific Teacher Information
• Retrieve only the first name, last name, and subject they teach from the
Teachers table.
• Tijaabi codeka hoose
• Select first_name, last_name, subject from teacher
3. Subjects Not Taught by Any Teacher
• Read all information in this table
4. Classroom Capacities
•Get a list of room numbers and their capacities from the Classrooms table.
5. Students Enrolled in a Specific Subject
• Read all information in this table

Page 3 of 3

You might also like