Junior — Middle
How can tables in databases be related to each other?
sobes.tech AI
Answer from AI
Tables in databases can be related to each other in the following main ways:
-
One-to-one relationship (1:1)
- Each record in the first table corresponds to exactly one record in the second.
- For example, the
Userstable and theProfilestable, where each user has one profile.
-
One-to-many relationship (1:N)
- One record in the first table is related to multiple records in the second.
- For example, the
Authorstable and theBookstable, where one author can have many books.
-
Many-to-many relationship (M:N)
- Records in the first table can be related to multiple records in the second and vice versa.
- Implemented through an intermediate join table.
- For example, the
Studentstable and theCoursestable, where a student can attend multiple courses, and a course can have many students.
Relationships are implemented using foreign keys, which ensure data integrity and allow joins between tables.