Composite primary keys can be used in two cases: 1) as identifiers for composite entities in many-to-many relationships, ensuring each combination is unique, and 2) as identifiers for weak entities, where the weak entity has a strong relationship to the parent entity. This is illustrated using a student-class enrollment example, where the composite primary key of student-class prevents a student enrolling in the same class twice. Weak entities represent real-world objects that depend on another for existence, and are modeled as two separate but strongly related entities. Composite and weak entities both benefit from composite primary keys maintaining integrity and consistency.