Sobes.tech
Middle

What types of relationships between tables exist in SQL?

sobes.tech AI

Answer from AI

In SQL, there are several main types of relationships between tables:

  • One-to-One: each record in the first table corresponds to exactly one record in the second. For example, a users table and a profiles table.

  • One-to-Many: one record in the first table corresponds to multiple records in the second. For example, one customer can have many orders.

  • Many-to-Many: records in the first table are related to multiple records in the second and vice versa. Usually implemented through a join table. For example, students and courses.

Relationships are implemented through foreign keys, which ensure data integrity and allow for joins to retrieve related data.