Junior — Middle
What types of relationships between tables in a database exist?
sobes.tech AI
Answer from AI
There are three main types of relationships between tables in databases:
-
One-to-One
- Each record in the first table corresponds to exactly one record in the second table.
- Example: the
Userstable and theProfilestable, where each user has one profile.
-
One-to-Many
- One record in the first table is related to multiple records in the second table.
- Example: the
Authorstable and theBookstable, where one author can have many books.
-
Many-to-Many
- Records in the first table can be related to multiple records in the second table and vice versa.
- Implemented through an intermediate table (e.g.,
Students,Courses, and theStudents_Coursestable).
These relationships help structure data and ensure data integrity in the database.