In the relational model, what exactly is a relation, and how do the SQL words table, row and column map onto relation, tuple and attribute?
answer
- heading = names + domains; body = set of tuples
- degree = attributes, cardinality = tuples
- tuple = mapping by name, not a list
- table/row/column ~ relation/tuple/attribute
- SQL leaks: bag, ordered columns, NULL
basics
~20 sA relation is a heading plus a body. The heading is a set of named attributes, each with a domain (type); the body is a set of tuples, each mapping every attribute name to a value. Informally: table = relation, row = tuple, column = attribute.
solid answer
~50 sRelation is a mathematical term, not relationship. A relation has a **heading** - a fixed, unordered set of attributes, where an attribute is a name plus a domain (the set of values it may take) - and a **body**, a set of tuples. A tuple maps every attribute in the heading to a value from that attribute's domain. Degree is the number of attributes, cardinality the number of tuples. Informally: table is a relation, row is a tuple, column is an attribute, declared type is the domain. The mapping is loose in three ways worth naming. An SQL table is a bag, so identical rows can coexist unless a uniqueness constraint forbids them. SQL columns have an ordinal position, while attributes are addressed only by name. SQL permits NULL, a marker that is not a member of any domain. So 'a table is a relation' is a useful shorthand, not an identity.
code
text · 3 linesCUSTOMER { customer_id: INTEGER, email: TEXT, signup_date: DATE }
degree = 3 (attributes in the heading)
cardinality = 4 (tuples currently in the body)go deeper
Recall the vocabulary cleanly: relation/tuple/attribute map to table/row/column, heading versus body, degree versus cardinality. Being able to say 'relation is not relationship' already puts you ahead.
Add that a tuple is a mapping addressed by name and that the body is a set, then name at least two ways SQL tables deviate (duplicates, NULL, ordinal columns).
Tie the model to engine behaviour: unordered, name-addressed data is exactly what lets the optimiser reorder and restructure work, and it is why code that relies on physical order is fragile.
Frame it as the contract boundary. The logical model deliberately withholds guarantees (order, position, storage) so implementations stay free; every leaked physical assumption in application code narrows what the platform can change later.
## Relation is a math term, not 'relationship' The word comes from set theory. Given domains (sets of values) D1, D2, ... Dn, the Cartesian product D1 x D2 x ... x Dn is the set of every combination of one value from each. A relation is any subset of that product, and each element of that subset is a tuple. Nothing in that definition mentions files, disk pages or foreign keys. A frequent beginner error is to hear 'relational database' and assume the relations are the links between tables. The relations are the tables. ## Heading and body A relation has two parts. The **heading** is a fixed, unordered set of attributes. An attribute is a pair: a name and a domain, where the domain is the set of values the attribute may take together with the operations defined on those values. `{customer_id: INTEGER, email: TEXT, signup_date: DATE}` is a heading of three attributes. The heading is the relation's type: it says what shape a tuple must have. The **body** is a set of tuples. A tuple maps every attribute name in the heading to a value drawn from that attribute's domain. Every tuple in the body carries exactly the same heading; a relation cannot have a ragged tuple with one extra attribute. Two derived numbers fall out: **degree** is the number of attributes in the heading, **cardinality** is the number of tuples in the body. ## Tuples are addressed by name, not by position Because the heading is a set of named attributes, a tuple is a mapping, not a list. In the model there is no 'third column' - there is the attribute named `signup_date`. Two tuples are equal exactly when they agree on the value of every attribute. That is why the model can declare column order irrelevant. ## What 'set of tuples' implies Sets are unordered. So a relation's body has no first tuple and no row numbers; any ordering you observe is a property of how you asked, not of the relation. ## Mapping onto SQL, and where it leaks Everyday speech, which interviewers expect you to use: table = relation, row = tuple, column = attribute, column type = domain, column count = degree, row count = cardinality. The deviations you should be able to name when pushed: - An SQL table is a **bag (multiset)**: without a uniqueness constraint two identical rows can coexist, so it is not strictly a set of tuples. - SQL gives columns an **ordinal position**; `SELECT *` returns them in declared order and some constructs address them by number. Relations have no such notion. - SQL allows **NULL**, a marker meaning 'no value here' that belongs to no domain, so an SQL row is not always a total mapping from attribute to domain value. - A table is a named, persistent, physically stored object; a relation is a pure value. ## Why the distinction earns its keep The heading/body split is what licenses the engine's freedom. Because the body is an unordered set and attributes are named rather than positional, the engine may lay rows out however it likes, return them in whatever order a plan produces, and rewrite or reorder work, as long as the resulting set of tuples is the same. When application code depends on something the model never promised - insertion order, a column's position - it is depending on an accident of the current physical layout, and that dependency breaks silently when the layout changes. The definitions also set up the rest of the theory: a key is a subset of the heading that uniquely determines a tuple in any body, and relational operators take relations and return relations, which is what makes them composable.
- Is a value inside a tuple identified by its position or by its attribute name?By attribute name. The heading is a set of attributes, and a set has no order, so a tuple is a mapping from name to value rather than an ordered list. Two tuples are equal when they agree on every named attribute, regardless of any order you might print them in. SQL layers an ordinal position on top of columns, but that position is an SQL convenience, not part of the relational model.
- Name concrete ways an SQL table fails to be a relation.A table without a uniqueness constraint is a multiset, so it can hold duplicate rows, while a relation body is a set. SQL columns have an ordinal position and can be referenced positionally, while attributes are name-addressed only. SQL allows NULL, which is a marker outside every domain, so a row need not be a total mapping from attribute to a domain value.
The heading is the form's list of labelled blanks; a tuple is one filled-in form. A stack of completed forms in a box is the body: no form is 'first' just because it happens to be on top.
saying these in an interview costs you the question
- Saying a relation is the relationship or foreign-key link between two tables
- Claiming tuples have an inherent order or a stable row number
- Treating column position as part of a row's identity
- Describing a relation as a file or physical storage structure rather than a value
- Asserting an SQL table is exactly a relation with no caveats about duplicates or NULL