chap 3 dbms
chap 3 dbms
Domain(D)
A Domain D is a set of atomic values , atomic means each value in the domain is indivisible.
Ex: Phone_numbers” are the set of 10 digit phone numbers valid.
Relation intension or Relation schema
A relation schema R is denoted by R (A1,A2,…..An)
Where R is the name of relation and list of attributes A1,A2,…..An. Attribute Ai is the name of a
role played by some D in the relation schema R. The domain of Ai is denoted by dom(Ai).
Characteristics of relations
1. Orderig of tuples in a relation
A relation is defined as a set of tuples, it has no order amog them. when we display a relation
as a table, the rows are display in certain order.
2. Ordering of values within a tuple and an alternative definition of a relation
A Relation shema R={A1,A2,….,An} is a set of attributes of a relation state r(R) is a finite
set of mapping of tuples, where each tuple ti is a mapping from R to D.
A tuple can be a set of(< attribute>,<value>) pairs, where each pair gives the value of the
mapping from attribute Ai to a value Vi from dom(Ai).
3. Values and nulls in a tuple.
Each value in a tuple is an atomic value. Null values which are used to represent the values
of attribute that may be unknown(or) may not apply to a tuple. A special value called NULL is used
in these cases.
4. interpretation[meaning] of relation
A Relation schema can be interpreted as a declaration (or) a type of assertion. Each tuple in
the relation can be interpreted as a fact or a particular instance of the assertion.
Constraints are conditions that must hold on all valid relation states . There are four main
types of constrains in the relational model:
Domain Constraint
Key Constraint
Entity Integrity Constraint
Referential Integrity Constraint
1] Domain constraint
It is specified within each tuple the value of each attribute(A) must be an atomic value from
the domain dom(Ai). Domains include data types like numeric, real numbers , character , Booleans,
strings.
2] Key constraint
The value of the attribute for different tuples in the relation has to be unique.
a) Super Key of R
Is a set of attributes SK of R with the following condition:
– No two tuples in any valid relation state r(R) will have the same value for SK
– That is, for any distinct tuples t1 and t2 in r(R), t1[SK] ≠t2[SK]
– This condition must hold in any valid state r(R)
b) Key of R
A "minimal" super key
– That is, a key is a super key K such that removal of any attribute from K results in a set of
attributes that is not a super key (does not possess the super key uniqueness property).
c) Candidate Key
A relation schema may have more than one key, each of the keys is called a candidate key.
d) Primary Key
The primary key values are used to identify tuples in the relation uniquely.
The primary key attributes are undertined
It provides the tuple identity also used to reference the tuple from another tuple.
e) Not Null
This constraint makes to enter a value to a attribute compulsorily.
3] Entity integrity constraint
The primary key attributes PK of each relation schema R in S cannot have null values in any
tuple of r(R).
This is because the primary key value is used to identify individual types in a relation
t[PK]=NULL for any tuple t in r(R)
if PK is several attributes, null is not allowed in only of these attributes
4] Referential integrity constraint
It is specified between two relations and used to maintain be consistency among tuples in the
two relations
Tuples in the referencing relation R1 have attributes FK called foreign key attribute that
reference the primary key attributes PK of the referenced relation R2.A tuple t1 in R1 is said to
reference a tuple t2 in R2 if t1[FK]=t2[PK]
A referential integrity constraint can be displayed in a relational database schema as a
directed are from R1, FK to R2
1] Insert a tuple
Insert may violate any of the constraints
a] Domain constraint : If one of the attribute values provided for the new tuple is not of the
specified attribute domain.
b] Key constraint : If the value of key attribute in the new tuple already exists in another tuple in the
relation
c] Entity integrity : If the primary key value is null in the new tuple
d] Referential integrity : If a foreign key value in the new tuple references a primary key value that
does not exist in the referenced relation.
2] Delete a tuple
Delete may violate only referential integrity
If the primary key value of the tuple being deleted is referenced from other tuples in the database.
Can be remedied by several actions: RESTRICT, CASCADE, SETNULL
a] RESTRICT option: reject the deletion
b] CASCADE option : propogate the new primary key value into the foreign keys of the referencing
tuples.
c] SET NULL option: set the foreign keys of the referencing tuples to NULL.
One of the above options must be specified during database design for each foreign key constraint.
3] Modify a tuple
UPDATE may violate domain constraint and NOT NULL constraint on an attribute being
modified.
Any of the other constraints may also be violated depending on the attribute being updated:
a] updating the primary key(PK) :similar to a DELETE followed by an INSERT need to specify
similar options to DELETE
b] updating a foreign key[FK] :may violate referential integrity
c] updating an ordinary attribute (neither PK for FK) : can only violate domain constraints.