Sub topic 1
The Relational Model: Relations, Tuples, and Schemas
Prerequisites
Assume that you know basic set theory, including sets, Cartesian products, and predicates. You should also recognize a database table, row, and column. Familiarity with simple SQL is helpful but not required.
Relations and tuples
The relational model represents data using relations. A relation is a set of tuples that follows a fixed schema. In a table, a relation looks like the table itself, and a tuple is one row of that table.
Consider this relation:
| sid | sname | age |
|---|---|---|
| 101 | Asha | 21 |
| 102 | Bilal | 20 |
| 103 | Chen | 22 |
Each row is a tuple, such as the tuple with values 101, Asha, and 21. The attributes are sid, sname, and age. An attribute is a named column that describes one component of each tuple.
A relation is conceptually a set, so it does not contain duplicate tuples, and tuple order does not matter. This differs from SQL, where query results normally behave like bags and can contain duplicates unless DISTINCT is used.
Schemas, domains, and instances
A relation schema describes the structure of a relation. It gives the relation name and its attributes. For example:
Student(sid, sname, age)The schema does not specify the current rows. The current collection of rows is the relation instance, or simply the instance. The schema is relatively stable, while the instance changes when rows are inserted, deleted, or updated.
Every attribute has a domain. A domain is the set of permitted values for that attribute. For example, sid may use positive integers, sname may use text strings, and age may use nonnegative integers. A tuple is valid only when each value belongs to the domain of its corresponding attribute.
The schema also determines the degree of a relation. Degree means the number of attributes. Student has degree three. The number of tuples is its cardinality. The displayed Student instance has cardinality three.
A relational database
A relational database contains several related relations. For example, Course(cid, cname) can describe courses, and Enrolled(sid, cid) can record which students take which courses. The value sid in Enrolled can refer to sid in Student, connecting the relations.
When solving GATE questions, first identify the attributes and their domains. Then count tuples and check whether each tuple satisfies the stated schema or constraints. Do not infer row order or assume that duplicate rows are meaningful in the relational model.
Exercise
A relation R(A, B, C) contains four tuples. What are the degree and cardinality of R?
Show answer
Its degree is 3 because it has three attributes. Its cardinality is 4 because it contains four tuples.