Skip to content
C

Relation


Relation

Definition

A relation is a set of tuples that conform to a relation schema. Formally, given a schema R(A1:D1, A2:D2, ..., An:Dn), a relation r on R is a finite subset of the Cartesian product D1 × D2 × ... × Dn. Because a relation is mathematically a set, it has two defining properties: no duplicate tuples, and no significance to the ordering of tuples.

Example

Using the running-example schema Students(id, name, department, gpa), one relation (a snapshot of data) might be the set:

{ (1,Asha,CS,8.7), (2,Ravi,ECE,7.9), (3,Meera,CS,9.1), (4,Karan,ME,6.8) }

This set of 4 tuples IS the relation on the Students schema at this moment.

How this differs from "Relation Schema" and "Table"

  • Relation Schema is the structure/blueprint (attribute names + domains) — fixed, like a class definition. A Relation is the actual data conforming to it — like an object/instance of that class.
  • A SQL table is the practical implementation, but SQL tables may allow duplicate rows and have an implementation-defined physical row order, so a table is not a pure relation in the strict mathematical sense unless duplicates are prevented (e.g., a key constraint) and ordering is never relied upon.

Edge Cases

  • Two relations written with tuples listed in different orders are the identical relation — order carries no meaning.
  • Inserting a tuple that is already present does not create a "new" relation — it's still the same set (though SQL would physically add a duplicate row unless a uniqueness constraint blocks it).
  • The empty set (zero tuples) is a perfectly valid relation — it has zero cardinality, but its schema and degree still exist.

Key Takeaways / Q&A

Q: Is a relation the same as a table? A: Practically, yes, in everyday usage — but formally a relation is duplicate-free and unordered, while a SQL table is not guaranteed to be either unless constrained.

Q: What determines whether two tuples belong to the same relation? A: They must conform to the same relation schema (same attributes, same domains).

Mock Test

  • Relation - Quick Test

    8 questions on Relation.

    8 questions · 8 min · Medium
    Start Mock Test