Junior — Middle
Explain the concept of Many-to-Many relationship in the context of databases.
sobes.tech AI
Answer from AI
A Many-to-Many relationship in databases means that one record in table A can be associated with multiple records in table B, and vice versa.
To implement such a relationship, an additional join table is usually created, which contains foreign keys to both related tables.
For example, in a course management system, students and courses are related Many-to-Many: one student can attend multiple courses, and one course can have many students.
Table structure:
students(id, name)courses(id, title)student_courses(student_id, course_id) — join table
This approach allows efficient storage and querying of data with multiple relationships between entities.