Você está na página 1de 13

Lecture 7

Relational Model
Relational Integrity
Views

1
Relational Integrity
Data models has two parts:
A manipulative part the types of operations
allowed on the data
A set of integrity rules ensure that the data is
accurate

Well see the later first

2
Relational Integrity
Integrity rules and constraints:
Domain Constraints
Entity integrity
Referential integrity
Enterprise Constraints

3
Relational Integrity
Every attribute has an associated domain set of values
allowed
Hence there are constraints called as domain constraints

Domain constraint specifies the set of data values that


are valid for a column and determines whether null values
are allowed

Domain integrity is enforced by validity checking and by


restricting the data type, format, or range of possible
values allowed in a column
Youll learn how to implement this using SQL

4
Relational Integrity
Null

Represents a value for an attribute that is currently


unknown or is not applicable for this tuple

Nulls are a way to deal with incomplete or exceptional


data

Not same as zero or spaces; zeros and spaces are


values but a null represents the absence of a value

5
Relational Integrity
Entity Integrity

In a base relation, no attribute of a primary key can be null


Entity (or Table) integrity requires that all rows in a
table have a unique identifier known as the primary
key value
Primary key cannot be a null value
Whether the primary key value can be changed, or

whether the whole row can be deleted, depends on

the level of integrity required between the primary 6


Relational Integrity
Referential Integrity

If foreign key exists in a relation, either the foreign key


value must match a candidate key value of some tuple in
its home relation or foreign key value must be wholly null

7
Relational Integrity
Referential Integrity
Referential integrity ensures that the relationship

between the primary key and the foreign key is always


maintained
A row in a referenced table cannot be deleted, nor can

the primary key be changed, if a foreign key refers to


the row
A row cannot be added to a referencing table if the

foreign key does not match the primary key of an


existing row in the referenced table

8
Relational Integrity
Enterprise Constraints

Additional rules specified by users or database


administrator

Allows you to define specific business rules that do not fall


into one of the other integrity categories

Triggering Operations - other rules to protect the validity of


attribute values;
should be removed from application programs and
9
incorporated into a repository in the dbms
Views
Base Relation
A named relation, corresponding to an entity in conceptual
schema, whose tuples are physically stored in database.

View
Dynamic result of one or more relational operations
operating on the base relations to produce another relation
its a derived relation

10
Views
A view is a virtual relation that does not actually exist
in the database but is produced upon request, at time of
request.
Contents of a view are defined as a query on one or
more base relations. Any operations on the view are
automatically translated into operations on underlying
relations.
Views are dynamic, meaning that changes made to
base relations that affect view attributes are immediately
reflected in the view.
When users make permitted changes to view, changes
11
are made to underlying relations.
Purpose of Views
View mechanism is desirable because:
It provides a powerful and flexible security mechanism
by
hiding parts of the database from certain users. Users are
not aware of the existence of any attributes or tuples
that
are missing from the view.
It permits users to access data in a way that is
customized
to their needs, so the same data can be seen by
different
users in different ways, at the same time
It can simply complex query operations on the base 12
Updating Views
All updates to a base relation should be immediately
reflected in all views that reference that base relation
Similarly, if a view is updated, then the underlying base
relation should reflect the change
However updates through views are:
- Allowed if the view defined using simple query and
derived from a single relation and contains either PK or

Candidate Key
- NOT allowed if the view defined derived from multiple
relations
- NOT allowed if the view defined involves aggregation or
13
grouping operations

Você também pode gostar