DBMS Unit2
DBMS Unit2
Introduction to
Relational Model
Example of a Relation
attributes
(or columns)
tuples
(or rows)
Attribute Types
The set of allowed values for each attribute is called the
domain of the attribute
Attribute values are (normally) required to be atomic; that is,
indivisible
The special value null is a member of every domain. Indicated
that the value is “unknown”
The null value causes complications in the definition of many
operations
Relation Schema and Instance
A1, A2, …, An are attributes
Example:
instructor = (ID, name, dept_name, salary)
Formally, given sets D1, D2, …. Dn a relation r is a subset of
D1 x D2 x … x Dn
Thus, a relation is a set of n-tuples (a1, a2, …, an) where each ai Di
The current values (relation instance) of a relation are specified by
a table
An element t of r is a tuple, represented by a row in a table
Relations are Unordered
The minimal set of attributes that can uniquely identify a tuple is known as a candidate
key.
It is a minimal super key.
It is a super key with no repeated data is called a candidate key.
The minimal set of attributes that can uniquely identify a record.
It must contain unique values.
It can contain NULL values.
Every table must have at least a single candidate key.
A table can have multiple candidate keys but only one primary key (the primary key cannot
have a NULL value, so the candidate key with a NULL value can’t be the primary key).
The value of the Candidate Key is unique and may be null for a tuple.
There can be more than one candidate key in a relationship.
Example
Conti..
Primary Key
If an attribute can only take the values which are present as values
of some other attribute, it will be a foreign key to the attribute to
which it refers. The relation which is being referenced is called
referenced relation and the corresponding attribute is called
referenced attribute the relation which refers to the referenced
relation is called referencing relation and the corresponding
attribute is called referencing attribute. The referenced attribute
of the referenced relation should be the primary key to it.
It is a key it acts as a primary key in one table and it acts as
secondary key in another table.
It combines two or more relations (tables) at a time.
They act as a cross-reference between the tables.
For example, DNO is a primary key in the DEPT table and a non-key
in EMP
Example
Composite Key