4 The Relational Data Model And Relational Database Constraint

Database Management System · Unit 4 · 3 hrs

The Relational Data Model and Relational Database Constraints

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

The Relational Data Model and Relational Database Constraints in short

This unit introduces the relational model itself: the formal notation used to talk about relations, tuples and attributes, the constraints every relational database must satisfy, and how insert, delete and update operations can violate those constraints.

The Relational Data Model and Relational Database Constraints: notes

Relational Model Concepts

The relational model represents a database as a collection of relations, informally, tables of values. Every row of the table is a tuple, representing one collection of related data values; every column has a distinct name and represents an attribute. A domain is the set of atomic, indivisible values permitted for a given attribute or column, for example the domain of a MaritalStatus attribute might be the set {Married, Single, Divorced}. A relation schema $R$ of degree $n$, written $R(A_1, A_2, \ldots, A_n)$, names the relation and lists its attributes; a relation state (or relation instance) $r(R)$ is the actual set of tuples currently populating that schema, and $|r|$, the number of tuples, is called the cardinality of that state at that moment.

Standard notation, used throughout the rest of the course, fixes uppercase letters $Q, R, S$ for relation names, lowercase $q, r, s$ for relation states, and $t, u, v$ for individual tuples. A tuple $t$ in a relation state $r(R)$ is written $t = \langle v_1, v_2, \ldots, v_n \rangle$, where $v_i$ is the value of attribute $A_i$ in $t$; both $t[A_i]$ and $t.A_i$ denote this value. When an attribute name could be ambiguous across relations, it is qualified with the relation name using dot notation, as in STUDENT.Name.

A relation, understood this way, has several defining characteristics: each relation has a name distinct from every other relation in the database; no two attributes of one relation may share a name; a relation never contains two identical tuples (duplicate tuples are not permitted); every tuple has exactly one value, possibly NULL, for every attribute; and, crucially, neither the tuples nor the attributes of a relation are considered to have any significant order, since a relation is mathematically a set (of tuples) built from a set (of attributes), not a sequence.

What this unit covers

  • Relational Model Concepts
  • Relational Model Constraints and Relational Database Schemas
  • Update Operations, Transactions, and Dealing with Constraint Violations

Relational Model Concepts

2080 · 5 marks

What is relational model? Define the terms domain, attribute, tuple and relation. [5]

Show solved answer

Relational Model

Definition

The relational model is a data model that represents data in the form of relations (tables). It was proposed by E.F. Codd and is the foundation of relational database management systems (RDBMS). In this model, all data is logically structured as two-dimensional tables consisting of rows and columns. SQL uses the terms table, row, and column for the formal relational model terms relation, tuple, and attribute respectively.


Key Terms

1. Domain

A domain is a set of atomic (indivisible) values from which the actual values of an attribute are drawn.

  • Domain constraints specify that within each tuple, the value of each attribute A must be an atomic value from the domain dom(A).
  • Data types associated with domains include:
    • Numeric types: integer, short integer, long integer, float, double
    • Other types: characters, Booleans, fixed-length strings, etc.

Example: The domain of an attribute "Age" could be the set of positive integers.


2. Attribute

An attribute is a named column of a relation that represents a specific property or characteristic of the entity being described.

  • Each attribute A takes values from its corresponding domain dom(A).
  • In SQL, attributes are referred to as columns.

Example: In a Student relation, Sname, Sid, and Address are attributes.


3. Tuple

A tuple is a single row in a relation that represents a single instance or record of the entity.

  • An n-tuple t in a relation r(R) is denoted as:

$$t = \langle v_1, v_2, \ldots, v_n \rangle$$

where $v_i$ is the value corresponding to attribute $A_i$.

  • Both t[Aᵢ] and t.Aᵢ refer to the value $v_i$ in tuple t for attribute $A_i$.
  • In SQL, tuples are referred to as rows.

Example: <101, "Ram", "Kathmandu"> is a tuple in a Student relation.


4. Relation

A relation is a two-dimensional table with rows and columns used to represent data and the relationships among data.

  • A relation r defined on a relation schema R(A₁, A₂, ..., Aₙ) is a set of n-tuples.
  • Each tuple in the relation contains one value for each attribute drawn from its domain.
  • A relation must satisfy integrity constraints such as domain constraints, key constraints, and referential integrity constraints.
  • In SQL, a relation is referred to as a table.

Example:

SidSnameAddress
101RamKathmandu
102SitaPokhara

This table is a relation with 2 tuples and 3 attributes.


Summary Table

Formal TermSQL EquivalentMeaning
RelationTableThe entire two-dimensional table
TupleRowA single record in the table
AttributeColumnA property/field of the relation
DomainData TypeSet of valid values for an attribute
Open this answer on its own page →

2080.1 · 5 marks

What is relational database? Explain different characteristic of a relation. Defain domain constraint. [5]

--- A relational database is a database that organizes and stores data in the form of tables (relations). Each table consists of rows (tuples) and columns (attributes). It is based on the relational data model proposed by E.F. Codd. Well-known DBMSs like Oracle, MS SQL Server, DB2, and MySQL supp...

Open this answer on its own page →

Relational Model Constraints and Relational Database Schemas

2078 · 5 marks

What is integrity? Explain different types of database integrity. [5]

Database integrity refers to the accuracy, consistency, and correctness of data stored in a database. It ensures that the data in the database remains valid and reliable throughout its lifecycle. Integrity constraints are rules or conditions specified on a database schema that must hold true for ...

Open this answer on its own page →

2076 · 5 marks

Differentiate between Integrity and Security with example. [5]

Database integrity refers to the correctness, accuracy, and consistency of data stored in the database. It ensures that the data follows certain rules (called integrity constraints) so that the data remains valid and meaningful at all times. : "The integrity constraints that are specified on data...

Open this answer on its own page →

2076 · 5 marks

Explain the use of primary and foreign key in DBMS with example. What is the role of foreign key? [5]

A primary key is an attribute (or a set of attributes) that uniquely identifies each tuple (row) in a relation (table). It must satisfy two properties: - Uniqueness: No two rows can have the same primary key value. - Not Null: The primary key attribute cannot be NULL. Eid Name Salary Address ----...

Open this answer on its own page →