3 Relational Data Model

Database Management System · Unit 3

Relational Data Model

Exam-focused notes for Relational Data Model (Database Management System, BIT202): what the TU syllabus asks and how it has actually been tested, with 5 solved past questions from this unit.

Relational Data Model in short

The relational model stores all data in tables. It is the base of nearly every modern database such as MySQL, Oracle, and PostgreSQL. This chapter explains its terms and the rules that keep data correct.

Relational Data Model: notes

Relational model definition

The relational model was proposed by E. F. Codd in 1970. It represents the database as a collection of relations. Each relation looks like a table of rows and columns. It rests on set theory and logic, so it has a strong mathematical base.

Main ideas:

  • Data is kept in tables (relations).
  • A row is a tuple, and a column is an attribute.
  • Every row can be told apart by a key.
  • Rows are linked through common values, not through physical pointers.
  • Operations are done with relational algebra or SQL.

Relations versus flat files

A flat file is a simple file where records are stored one after another, such as a text or CSV file. A relation is a table with rules.

Flat fileRelation (table)
No fixed rules for data typesEach attribute has a domain
No key needed, duplicates allowedRows are unique, identified by a key
No links between filesTables linked by foreign keys
Repeated data, hard to updateLess redundancy through design
Program must know the file layoutAccess through SQL, layout hidden
No integrity checkingIntegrity constraints enforced

Properties of a relation: no duplicate tuples, tuple order has no meaning, attribute order has no meaning, and every value is atomic (one single value).

What this unit covers

  • Relational model definition
  • Relations versus flat files
  • Relation, instance, and schema
  • Attributes and domains
  • Primary keys and foreign keys
  • Integrity constraints
  • Referential integrity

Relation, instance, and schema

2080 · 5 marks

Define relation, instance and schema. Explain with example [5]

A relation is a table with rows and columns. In the relational model, a relation is a mathematical concept based on set theory. It consists of: - A name (the relation name) - A set of attributes (columns) - A set of tuples (rows) A relation can be thought of as a two-dimensional table that stores...

Open this answer on its own page →

Relations versus flat files

2079 · 5 marks

What is Relational Data model? How Relation is different than Flat file? [5]

The Relational Data Model is a data model that represents data in the form of two-dimensional tables called relations. It was proposed by E.F. Codd in 1970 and is the foundation of most modern database management systems (RDBMS). Term Description ------------------- Relation A table with rows and...

Open this answer on its own page →

Primary keys and foreign keys

2078 · 5 marks

What is Primary key and Foreign Key? Why is this required in the DBMS? [5]

--- A Primary Key is a column (or a set of columns) in a table that uniquely identifies each row/record in that table. - Must be unique for every record (no two rows can have the same primary key value) - Cannot contain NULL values - A table can have only one primary key - It provides a unique id...

Open this answer on its own page →

Integrity constraints

2078 · 5 marks

What is Integrity constraint? What are the three main categories of Integrity constraints. [5]

Show solved answer

Integrity Constraints

Definition

An Integrity Constraint is a rule or condition imposed on a database to ensure the accuracy, consistency, and validity of data stored in the database. Integrity constraints prevent invalid data from being entered into the database and maintain the correctness of data throughout all operations (insertion, deletion, and update).


Three Main Categories of Integrity Constraints

1. Domain Integrity Constraints

  • These constraints specify that the value of each attribute must be an atomic value from its domain (data type).
  • They restrict the type, format, and range of values that can be stored in a column.
  • Example: An attribute Age must contain only positive integer values; a Gender attribute may only accept 'M' or 'F'.

2. Entity Integrity Constraints

  • This constraint states that the primary key of a relation must be unique and not null.
  • Every tuple (row) in a relation must be uniquely identifiable.
  • No attribute that is part of the primary key can have a NULL value.
  • Example: In a Student table, the StudentID (primary key) must have a unique, non-null value for every student record.

3. Referential Integrity Constraints

  • This constraint is defined between two relations and is used to maintain consistency among tuples.
  • It states that a foreign key in one relation must either match a primary key value in the referenced relation, or be NULL.
  • It ensures that references between tables remain valid.
  • Example: In an Enrollment table, the StudentID (foreign key) must correspond to an existing StudentID in the Student table.

Summary Table

ConstraintApplies ToKey Rule
Domain IntegrityAttribute valuesValues must be within defined domain
Entity IntegrityPrimary KeyMust be unique and not null
Referential IntegrityForeign KeyMust match a primary key or be null
Open this answer on its own page →

0 · 5 marks

Define domain constraint and referential integrity constraint. [5]

--- Definition: A domain constraint specifies that the value of each attribute in a relation must be an atomic (indivisible) value drawn from the domain (set of permissible values) defined for that attribute. In other words, for every tuple in a relation, the value of each attribute must belong t...

Open this answer on its own page →