*Constraints on Relations*

On March 21, 2014, In Relational Algebra by Admin

Views (1506)

Relational algebra offers a means to express common constraints, such as the referential integrity constraints introduced in "The Modeling of Constraints". Actually, we shall see that relational algebra provides us convenient ways to express a large variety of other constraints. Even functional dependencies can be expressed in relational algebra, as we shall see in "Additional Constraint Examples" Example 1. Constraints are very important in database programming, and we shall cover in "Multimedia Networking" how SQL database systems can enforce the same types of constraints as we can express in relational algebra.

### Relational Algebra as a Constraint Language

There are two ways in which we can use expressions of relational algebra to express constraints.1. If R is an expression of relational algebra, then is a constraint that says "The value of R must be empty", or equivalently "There are no tuples in the result of R".

2. If R and S are expressions of relational algebra, then is a constraint that says "Every tuple in the result of R must also be in the result of S". Of course the result of S may contain additional tuples not produced by R.

These ways of expressing constraints are in fact equivalent in what they can express, but sometimes one or the other is clearer or more brief. That is, the constraint could just as well have been written To see why, notice that if every tuple in R is also in S, then surely R - S is empty. On the other hand, if R - S contains no tuples, then every tuple in R must be in S (or else it would be in R - S).

However, a constraint of the first form, , could just as well have been written . Technically, is not an expression of relational algebra, but since there are expressions that evaluate to , such as R - R, there is no harm in using as a relational-algebra expression. Note that these equivalences hold even if R and S are bags, provided we make the conventional interpretation o.f : each tuple t appears in S at least as many times as it appears in R.

In the next sections, we shall see how to express important constraints in one of these two styles. As we shall see in "Multimedia Networking", it is the first style - equal-to-the-emptyset - that is most frequently used in SQL programming. On the other hand, as shown above, we are free to think in terms of set-containment if we wish and later convert our constraint to the equal-to-the-emptyset style.

### Tags

- relational algebra
- functional dependencies
- database programming
- tuple
- Queries in PSM
- Using Shared Variables
- System Aspects of SQL
- Instead-Of Triggers
- Constraints on Attributes and Tuples
- Deferring the Checking of Constraints
- Maintaining Referential Integrity
- Declaring Foreign-Key Constraints
- Interpreting Queries Involving Views
- Full-Relation Operations
- Natural Joins / Outerjoins
- Subqueries in FROM Clauses
- Correlated Subqueries
- Conditions Involving Tuples
- Subqueries
- Union, Intersection, and Difference of Queries
- Interpreting Multirelation Queries
- Queries Involving More Than One Relation
- The Truth-Value UNKNOWN
- Selection in SQL
- The Database Language SQL
- Additional Constraint Examples
- Referential Integrity Constraints
- Extending the Projection Operator
- Extended Operators of Relational Algebra
- Selection on Bags / Product of Bags / Joins of Bags
- Relational Operations on Bags
- A Linear Notation for Algebraic Expressions
- Dependent and Independent Operations
- Renaming
- Combining Operations to Form Queries
- Natural Joins / Theta-Joins
- Set Operations on Relations
- An Algebra of Relational Operations
- Relational Algebra
- Object-Oriented Versus Object-Relational
- References
- Nested Relations
- Representing Set-Valued Attributes
- From ODL Designs to Relational Designs
- Reasoning About Multivalued Dependencies
- Roles in Relationships
- Instances of an E/R Diagram
- Database Programming
- The Query Processor