Relational Model & Keys
The relational model
In the relational data model, proposed by E. F. Codd, all data is stored in tables. Each table is called a relation. Tables are linked through common columns, so data is not repeated.
| RollNo | Name | Class | City |
|---|---|---|---|
| 101 | Aarav | XI-A | Jaipur |
| 102 | Sana | XI-A | Lucknow |
| 103 | Kabir | XI-B | Jaipur |
| 104 | Diya | XI-B | Pune |
Relational terms
| Term | Everyday word | In STUDENT |
|---|---|---|
| Relation | Table | STUDENT |
| Attribute | Column / field | RollNo, Name, Class, City |
| Tuple | Row / record | (102, 'Sana', 'XI-A', 'Lucknow') |
| Domain | Set of allowed values of an attribute | Class ∈ {XI-A, XI-B, XI-C} |
| Relation schema | Table design | STUDENT(RollNo, Name, Class, City) |
| Relation state / instance | Data present right now | the 4 rows shown |
Degree and cardinality
Degree
- Number of attributes (columns)
- STUDENT has degree 4
- Changes only when the design changes
Cardinality
- Number of tuples (rows)
- STUDENT has cardinality 4
- Changes every time rows are added or deleted
Properties of a relation
- Each attribute has a unique name within the table.
- The order of columns and of rows does not matter.
- No two tuples are exactly the same.
- Each cell holds a single (atomic) value — not a list.
- All values in a column come from the same domain (same type).
Keys in a relational database
A key is an attribute (or a set of attributes) that helps identify rows uniquely or link tables.
Foreign key and relationships
The FEE table stores RollNo to say whose fee it is. RollNo in FEE is a foreign key that refers to the primary key RollNo of STUDENT. A foreign-key value must either match an existing primary-key value or be NULL — you cannot record a fee for a student who does not exist. This rule is called referential integrity.
| ReceiptNo | RollNo | Month | Amount |
|---|---|---|---|
| R1 | 101 | April | 3500 |
| R2 | 102 | April | 3500 |
| R3 | 101 | May | 3500 |
NULL values
NULL means "value unknown or not applicable". It is not zero and not an empty string. Example: a new student whose phone number is not yet known. A primary key can never be NULL.
Summary & practice
- Relation = table; attribute = column; tuple = row; domain = allowed values.
- Degree = number of columns; cardinality = number of rows.
- Candidate keys → one chosen as primary (unique, not null); rest are alternate keys.
- Foreign key links a child table to a parent table's primary key.
Table EMPLOYEE(EmpID, Name, Email, Phone, DeptID) has 25 rows. DEPARTMENT(DeptID, DeptName) has 5 rows. 1) Degree and cardinality of EMPLOYEE? 2) Candidate keys of EMPLOYEE? 3) Which attribute is a foreign key?
Answers: 1) degree 5, cardinality 25. 2) EmpID, Email, Phone (if each is unique). 3) DeptID in EMPLOYEE.
