0% found this document useful (0 votes)
55 views9 pages

Overview of Relational Model Concepts

Unit 2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views9 pages

Overview of Relational Model Concepts

Unit 2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

18

Unit-2
Introduction to Relational Model:
Table or Relation: Collection of related records.
The columns of this relation are called Fields, Attributes or Domains. The rows are called Tuples
or Records.

Relational model constraints over relations:


The constraints can be classified into 4 types as below:
1. Domain Constraints
2. Key Constraints
3. Entity Integrity Constraints.
4. Referential Integrity Constraints.
1. Domain Constraints
Domain constraints are the most elementary form of integrity constraints. They are tested easily
by the system whenever a new data item is entered into the database. Domain constraints specify
the set of possible values that may be associated with an attribute. Such constraints may also
prohibit the use of null values for particular attributes. The data types associated with domains
typically include standard numeric data types for integers A relation schema specifies the domain
of each field or column in the relation instance. These domain constraints in the schema specify
an important condition that each instance of the relation to satisfy: The values that appear in a
column must be drawn from the domain associated with that column. Thus the domain of a field
is essentially the type of that field.
2. Key Constraints
A key constraint is a statement that a certain minimal subset of the fields of a relation is a unique
identifier for a tuple. Example:
The ‘students’ relation and the constraint that no 2 students have the same student id (sid).
3. Entity Integrity Constraints
This states that no primary key value can be null. The primary key value is used to identify
individual tuples in a relation. Having null values for the primary key implies that we cannot
identify some tuples. NOTE: Key Constraints, Entity Integrity Constraints are specified on
individual relations. PRIMARY KEYS comes under this.
4. Referential Integrity Constraints
The Referential Integrity Constraint is specified between 2 relations and is used to maintain the
consistency among tuples of the 2 relations. Informally, the referential integrity constraint states
that ‘a tuple in 1 relation that refers to another relation must refer to an existing tuple in that
relation. We can diagrammatically display the referential integrity constraints by drawing a
directed arc from each foreign key to the relation it references. The arrow head may point to the
primary key of the referenced relation.
19

Relational Algebra:
Selection and Projection:
Relational algebra includes operators to select rows from a relation (σ)and to project columns (π).
These operations allow us to manipulate data in a single relation. Con-sider the instance of the
Sailors relation shown in fig. 1, denoted as S2. We can retrieve rows corresponding to expert
sailors by using the σ operator. The expression

evaluates to the relation shown in fig. 2. The subscript rating>8 specifies the selection criterion to
be applied while retrieving tuples.

Fig. 1. Instance S1 of sailors

Fig. 2.
The selection operator σ specifies the tuples to retain through a selection condition. In general, the
selection condition is a boolean combination (i.e., an expression using the logical connectives ^
and) of terms that have the form attribute op constant or attribute1 op attribute2, where op is one
of the comparison operators <, <=, =, 6=,>=, or >. The reference to an attribute can be by position
(of the form .i or i) or by name (of the form .name or name). The schema of the result of a selection
is the schema of the input relation instance.
The projection operator π allows us to extract columns from a relation; for example, we can find
out all sailor names and ratings by using π. The expression

evaluates to the relation shown in Figure 3.


20

Fig. 3.
The subscript sname,rating specifies the fields to be retained; the other fields are `projected out.'
The schema of the result of a projection is determined by the fields that are projected in the obvious
way.
Suppose that we wanted to find out only the ages of sailors. The expression,

evaluates to the relation,

Set Operations:
21
22

Relational Calculus:
Relational calculus is an alternative to relational algebra. In contrast to the algebra, which is
procedural, the calculus is nonprocedural, or declarative, in that it allows us to describe the set
of answers without being explicit about how they should be computed.
The variant of the calculus that we present in detail is called the tuple relational calculus (TRC).
Variables in TRC take on tuples as values.
In another variant, called the domain relational calculus (DRC), the variables range over field
values.
23

Tuple Relational Calculus:


24
25

Domain Relational Calculus:


26

Common questions

Powered by AI

Relational algebra is a procedural query language that requires a user to specify a sequence of operations to fetch data from the database, whereas relational calculus is a non-procedural query language, where the user specifies what data is needed without specifying how to retrieve it . Relational algebra uses operators such as selection (σ) and projection (π) to manipulate data . In contrast, relational calculus, particularly the tuple relational calculus (TRC) and domain relational calculus (DRC), provides a declarative way to describe the set of results .

Relational model constraints are rules that ensure data integrity and accuracy within a database. They include domain constraints, key constraints, entity integrity constraints, and referential integrity constraints. Domain constraints restrict the set of allowable values for an attribute, ensuring data type consistency . Key constraints, such as primary keys, ensure that tuples are uniquely identifiable . Entity integrity constraints prevent null values in primary keys, maintaining data uniqueness . Referential integrity constraints maintain consistency across related tables by ensuring that references between them are valid . These constraints are crucial, as they prevent data anomalies, maintain consistency, and ensure reliable operation of the database system.

Allowing null values in primary keys would lead to an inability to uniquely identify tuples in a relation, potentially causing data integrity issues such as duplicates and inconsistencies . Entity integrity constraints address this issue by explicitly stating that no primary key can be null, ensuring every entry in a relation is identifiable and distinct, thus maintaining the integrity and reliability of the data .

Using a procedural query language like relational algebra requires specifying a sequence of specific operations to retrieve the desired result, which can be beneficial for understanding the explicit process of data manipulation and optimization opportunities . However, this might also increase complexity for users as they have to detail each step. In contrast, a non-procedural language like relational calculus allows users to express what they want without detailing how to get it, leading to simpler queries and potentially less error-prone operations . This can result in better overall usability for complex queries, though it might offer less control over specific query optimization techniques.

Referential integrity constraints can be visually represented by a directed arc connecting a foreign key in one relation to the primary key it references in another relation . This indicates that for any tuple in the first relation, the tuple's foreign key must match an existing primary key in the second relation, ensuring that all references between tables are valid and the referenced data exists .

The selection operation (σ) in relational algebra is used to extract rows from a relation based on a specified criterion, such as a boolean combination of terms involving attributes and constants. For example, selecting sailors with a rating greater than 8 would involve an expression like σrating>8(Sailors). The projection operation (π) is used to extract specific columns from a relation, for example, retrieving only the names and ratings of sailors would involve the operation πsname,rating(Sailors), which omits other fields .

Domain constraints are used to define the permissible set of values for each attribute within a relation schema, ensuring data integrity by restricting inputs to a certain type or set of values . They are enforced automatically by the database management system whenever a new data item is entered, typically through specifying data types and prohibiting null values for specific attributes .

Key constraints ensure that a specified set of fields within a table uniquely identifies each tuple, preventing duplicate entries and maintaining data integrity within that table . If these constraints are not enforced, there can be risks of duplicate records, which can lead to data redundancy, inconsistency, and unreliable query results .

Entity integrity constraints ensure that every table has a primary key and that this key cannot have null values, which is crucial for uniquely identifying each record in a table and avoiding data ambiguity . Referential integrity constraints ensure consistency between tables by mandating that a tuple in one table that refers to another must reference an existing, valid tuple in the related table . Together, these constraints prevent data anomalies and maintain data reliability within the database.

Tuple relational calculus (TRC) and domain relational calculus (DRC) both provide means to query databases without specifying how to retrieve data, but they differ in their approach. TRC focuses on retrieving whole tuples based on a condition, offering flexibility when working with entire records . In contrast, DRC focuses on individual field values, allowing for more granular and precise queries at the attribute level . This can provide users with more flexibility in terms of extracting specific parts of data they are interested in.

You might also like