0% found this document useful (0 votes)
32 views

04-Relational Model and Keys

The document discusses the relational database model and relational database terminology. It defines key concepts like relations, attributes, tuples, domains, keys such as candidate keys, primary keys, foreign keys and provides examples to illustrate these concepts.

Uploaded by

MANI 96 FF
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)
32 views

04-Relational Model and Keys

The document discusses the relational database model and relational database terminology. It defines key concepts like relations, attributes, tuples, domains, keys such as candidate keys, primary keys, foreign keys and provides examples to illustrate these concepts.

Uploaded by

MANI 96 FF
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
You are on page 1/ 32

Database Systems

Relational Model
& Keys
Dr. Maqbool Khan

1 www.pktutorials.com
Relational Model:

▪ Based on the mathematical concept of a relation.


▪ Relational model was first proposed by Dr. E. F. Codd in 1970

Objectives:
▪ Allow a high degree of data independence.
▪ Provide base for dealing with data semantics, consistency, and redundancy
problems (Normalized relations).
▪ Expansion of set-oriented data manipulation languages.

2 www.pktutorials.com
Relational Model:
▪ First project by IBM in 1970 was the prototype relational DBMS System R,
that led to:
▪ The development of a structured query language called SQL.
▪ The production of various commercial RDBMS products during the late
1970s and the 1980s, For example:
DB2 and SQL/DS from IBM and Oracle from Oracle Corporation.

▪ The second project to have been significant in the development of the


relational model was the INGRES (Interactive Graphics Retrieval System)
at UC Berkeley.

3 www.pktutorials.com
Relational Database Terminology:

Relation is a table with columns and rows. Only applies to logical structure of
the database, not the physical structure.
Attribute is a named column of a relation.
Domain is the set of allowable values for one or more attributes.
Tuple is a row of a relation.

4 www.pktutorials.com
Relational Database Terminology:

Degree is the number of attributes in a relation.


Cardinality is the number of tuples in a relation.
Relational Database is a collection of normalized relations with distinct relation
names.
Typically means that the only shared columns among relations are foreign keys
(eliminates redundancy).

5 www.pktutorials.com
Alternative Terminology for Relational Model:

Formal Term Alternative 1 Alternative 2

Relation Table File

Tuple Row Record

Attribute Column Field

6 www.pktutorials.com
Examples: Branch and Staff Relations:

7 www.pktutorials.com
Examples of Attribute Domains:

8 www.pktutorials.com
Mathematical Definition of Relation:

▪ Consider two sets, D1 & D2, where D1 = {2, 4} and D2 = {1, 3, 5}.
▪ Cartesian product, D1 × D2, is set of all ordered pairs, where first element is
member of D1 and second element is member of D2.
D1 × D2 = {(2, 1), (2, 3), (2, 5), (4, 1), (4, 3), (4, 5)}
▪ Alternative way is to find all combinations of elements with first from D1
and second from D2.

9 www.pktutorials.com
Mathematical Definition of Relation:
Any subset of Cartesian product is a relation; e.g.
R = {(2, 1), (4, 3)}
May specify which pairs are in relation using some condition for selection e.g.
second element is 1:
R = {(x, y) | x ∈D1, y ∈D2, and y = 1}
R = {(2, 1), (4, 1)}

First element is always twice the second:


S = {(x, y) | x ∈D1, y ∈D2, and x = 2y}

S = {(2,1)}

10 www.pktutorials.com
Mathematical Definition of Relation:

Consider three sets D1, D2, D3 with Cartesian Product D1 × D2 × D3; e.g.
D1 = {1, 3}
D2 = {2, 4}
D3 = {5, 6}

D1 × D2 × D3 = {(1,2,5), (1,2,6), (1,4,5),


(1,4,6), (3,2,5), (3,2,6), (3,4,5), (3,4,6)}

▪ Any subset of these ordered triples is a relation.

11 www.pktutorials.com
Mathematical Definition of Relation:
Cartesian product of n sets (D1, D2, . . ., Dn) is:
D1 × D2 × . . . × Dn = {(d1, d2, . . . , dn) | d1 ∈D1, d2 ∈D2, . . . , dn∈Dn}
usually written as:

Any set of n-tuples from this Cartesian product is a relation on the n sets.

12 www.pktutorials.com
Database Relations:
Relation schema
▪ Named relation defined by a set of attribute and domain name pairs.
▪ Let A1, A2, . . . , An be attributes with domains D1, D2, . . . , Dn. Then the set {A1:D1,
A2:D2,. . . , An:Dn} is a relation schema.

▪ In our example, the Branch relation has attributes branchNo, street, city, and
postcode, each with its corresponding domain.
▪ relation instance {(branchNo: B005, street: 22 Deer Rd, city: London,
postcode: SW1 4EH)}

13 www.pktutorials.com
Database Relations:

Relational database schema

▪ Set of relation schemas, each with a distinct name.

▪ If R1, R2, . . . , Rn are a set of relation schemas, then we can write the relational
database schema, or simply relational schema, R, as:

R = {R1, R2, . . . , Rn}

14 www.pktutorials.com
Properties of Relations:

▪ Relation name is distinct from all other relation names in relational schema.
▪ Each cell of relation contains exactly one atomic (single) value. (e.g., a phone
field may not contain multiple phone numbers)
▪ Each attribute has a distinct name.
▪ Values of an attribute are all from the same domain.
▪ Each tuple is distinct; there are no duplicate tuples.
▪ Order of attributes has no significance.
▪ Order of tuples has no significance, theoretically.

15 www.pktutorials.com
Relational Keys:

▪ Candidate Key
▪ Primary Key
▪ Super Key
▪ Alternate Key
▪ Foreign Key
▪ Composite Key

16 www.pktutorials.com
Candidate Key:
▪ The minimal set of attributes that can uniquely identify a tuple is known as a
candidate key. For Example, STUD_NO in STUDENT relation.

▪ 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 and It can also 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 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.

17 www.pktutorials.com
Candidate Key:
The candidate key can be simple (having only one attribute) or composite as well.

18 www.pktutorials.com
Primary Key:
▪ There can be more than one candidate key in relation out of which one can be
chosen as the primary key.

▪ It is a unique key.
▪ It can identify only one tuple (a record) at a time.
▪ It has no duplicate values, it has unique values.
▪ It cannot be NULL.
▪ Primary keys are not necessarily to be a single column; more than one column
can also be a primary key for a table.

19 www.pktutorials.com
Primary Key:

20 www.pktutorials.com
Super Key:
▪ The set of attributes that can uniquely identify a tuple is known as Super Key.

▪ Adding zero or more attributes to the candidate key generates the super key.
▪ A candidate key is a super key but vice versa is not true.
▪ Super Key values may also be NULL.

21 www.pktutorials.com
Super Key:

22 www.pktutorials.com
Alternate Key:
▪ The candidate key other than the primary key is called an alternate key.

▪ All the keys which are not primary keys are called alternate keys.
▪ It is a secondary key.
▪ It contains two or more fields to identify two or more records.
▪ These values are repeated.
▪ Eg:- SNAME, and ADDRESS is Alternate keys

23 www.pktutorials.com
Alternate Key:

24 www.pktutorials.com
Foreign Key:

▪ 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

25 www.pktutorials.com
Foreign Key:

26 www.pktutorials.com
Composite Key:
▪ It acts as a primary key if there is no primary key in a table
▪ Two or more attributes are used together to make a composite key.
▪ Different combinations of attributes may give different accuracy in terms of
identifying the rows uniquely.

27 www.pktutorials.com
Relational Keys:

28 www.pktutorials.com
Relational Keys:

29 www.pktutorials.com
Relational Keys:

30 www.pktutorials.com
Representing Relational Database Schemas

A relational database consists of any number of normalized relations. The


relational schema for part of the DreamHome case study is:

Book Page No. 159

31 www.pktutorials.com
THANKS

32 3/12/2024 www.pktutorials.com

You might also like