1 of 41

CS-10337 – Applied Database Technologies� Lecture 3

By Prof. Rafael Orta

2 of 41

Wayground

3 of 41

Last class we covered

  • Validating your Elvis Access
  • Data Types
  • Creating Databases
  • Creating tables
  • Creating Indexes

4 of 41

Agenda

Lab assignment #1

Relationships

Referential Integrity

Quiz #1

5 of 41

Lab #1

Objective:

• Explore relationships, referential integrity, and indexing in MySQL�• Practice joins, aggregates, and performance analysis

Schema Provided: CS10337_Orta (read-only)

Tables: departments, students, professors, courses, enrollments�Views: v_student_courses, v_course_roster, v_dept_enrollment_summary

Deliverables: SQL file & Screenshots

6 of 41

Lab #1

Tasks

Warm-up (selects & joins)

1.- Students and Majors – Show each student with their major department name.

2.- Course Roster – List the roster for 1001 in Fall-2025 with student name and grade.

3.- Professor’s Courses – List all course codes and titles taught by Dr. Elena Ruiz.

4.- Unenrolled Students – Show students not enrolled in any course in Fall 2025.

5.- Top courses by enrollments: Show the courses ordered by the highest enrollment first.

7 of 41

Lab #1- Help

DEMO TIME – Querying the Database

8 of 41

Lab #1- Help

1.- Students and Majors�Show each student with their major department name.�Hint: students → departments.

2.- Course Roster�List the roster for CS101 in Fall-2025 showing student name and grade.�Hint: Filter v_course_roster or join courses, enrollments, students.

3.- Professor’s Courses�List all course codes and titles taught by Dr. Elena Ruiz.

4.- Unenrolled Students�Show students who are not enrolled in any course in Fall-2025.�Hint: LEFT JOIN to enrollments + WHERE e.enrollment_id IS NULL.

5.- Top courses by enrollment�Using v_course_roster

9 of 41

Relationships

What do you think is the

Relational Database Model?

10 of 41

Relationships

11 of 41

Relationships

12 of 41

Relationships

13 of 41

Relationships

14 of 41

Relationships

15 of 41

Relationships

16 of 41

Relationships

One professor can have many students, and one student can have many professors.

One student can have many classes.

One student can have only one dorm room.

17 of 41

Relationships

18 of 41

Supplemental Video(s)

19 of 41

Supplemental Reading

20 of 41

Knowledge Check

Which of the following is the best example of a many-to-many relationship?

A. Each employee is assigned to exactly one company car.�B. A student can enroll in many courses, and each course can have many students.�C. Each country has one capital city.�D. A customer places one order at a time.

Correct Answer: B

21 of 41

Referential Integrity

Primary Key

Think of a primary key as the unique ID card for each row in a table.

  • No two rows can share the same value.
  • It can’t be empty (NULL).
  • It guarantees that every record is uniquely identifiable.

Foreign Key

A foreign key is like a reference or pointer. It links a row in one table to a related row in another.

  • It enforces relationships between tables.
  • Prevents inserting values that don’t exist in the parent table (referential integrity).

22 of 41

Referential Integrity

23 of 41

Referential Integrity

24 of 41

Referential Integrity

25 of 41

Referential Integrity

26 of 41

Referential Integrity

27 of 41

Referential Integrity

28 of 41

Referential Integrity

29 of 41

Referential Integrity

Any real live resemblance to the character in the picture is only in your mind ->

30 of 41

Referential Integrity

31 of 41

Referential Integrity

32 of 41

Referential Integrity

33 of 41

Referential Integrity

34 of 41

Referential Integrity

35 of 41

Supplemental Video(s)

36 of 41

Supplemental Reading

37 of 41

Knowledge Check

Which statement best describes referential integrity in databases?

A. It guarantees every column in a table is unique.�B. It prevents inserting a child record without a matching parent record.�C. It ensures that every row in a table has a primary key.�D. It allows duplicate values in the primary key column.

Correct Answer: B

38 of 41

Attendance

39 of 41

Quiz #1

40 of 41

Reference Material used in this presentation

  • Murach’s MySQL 3rd Edition.
  • Fundamentals of Database Systems, 7th Edition by Elmasnri
  • Proprietary Material by the author.
  • Material from Professor Jack Mayers.
  • Material from Professor Phillip Quinn.

41 of 41