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

Lecture 4 Relational Model

This document contains lecture slides on relational database systems from COMSATS University Islamabad. The slides cover relational data terminology, the relational model, examples of relations between branches and staff, the mathematical definition of relations, relational keys, representing relational database schemas, and integrity constraints. The slides are based on textbooks by Thomas Connolly and Jeffry Hoffer and include code snippets and examples from other sources.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Lecture 4 Relational Model

This document contains lecture slides on relational database systems from COMSATS University Islamabad. The slides cover relational data terminology, the relational model, examples of relations between branches and staff, the mathematical definition of relations, relational keys, representing relational database schemas, and integrity constraints. The slides are based on textbooks by Thomas Connolly and Jeffry Hoffer and include code snippets and examples from other sources.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

COMSATS University Islamabad

cuiatd.edu.pk
subexpert.com
Abbottabad Campus
Computer Science Department
subexpert.com

DATABASE SYSTEMS

Lecture 4 – Relational Model

Mukhtiar Zamin,
MS (Computer Science)
Iowa, United States of America
[email protected]

1
ACKNOWLEDFMENT
subexpert.com
Lectures are prepared from the following books:
Text Book:
– Database Systems, A practical approach to Design, Implementation and Management
by Thomas Connolly, 4th edition

Other Books:
– Modern Database Management
by Jeffry A. Hoffer, 10th Edition
– Microsoft SQL Server 2008 Database Development
by Microsoft

In addition there are other examples and code snippets from other sources which are
mentioned on respective slides

2
Lecture 4
• Relational Model
• subexpert.com
Relational Data Terminologies
• Examples: Branch and Staff Relations
• Mathematical Definition of Relation
• Examples - Attribute Domains
• Database Relations
• Properties of Relations
• Relational Keys
• Representing Relational Database Schemas
• Integrity Constraints
• Views
– Updating Views
– Purpose of Views

3
Relational Data Terminologies
subexpert.com
• Relation
– A relation is a table with columns and rows.
– Only applies to logical structure of the database,
not the physical structure.
• Attribute
– Attribute is a named column of a relation.
• Domain
– Domain is the set of allowable values for one or
more attributes.
4
Relational Model
subexpert.com
• Based on the mathematical concept of a relation
• Relational model was first proposed by E. F. Codd in 1970
will following 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
• First project by IBM’s in 1970 was the prototype relational
DBMS System R and led to
– the development of a structured query language called SQL
– production of various commercial relational DBMS products

5
Relational Data Terminologies
subexpert.com
• Tuple
– Tuple is a row of a relation.
• Degree
– Degree is the number of attributes in a relation.
• Cardinality
– Cardinality is the number of tuples in a relation.
• Relational Database
– Relational Database is a collection of normalized relations with distinct
relation names.
Formal Term Alternative 1 Alternative 2
Relation Table File
Tuple Row Record
Attribute Column Field

6
Examples: Branch and Staff Relations
subexpert.com

7
Mathematical Definition of Relation
subexpert.com
• 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.
• Any subset of Cartesian product is a relation; e.g. R = {(2, 1), (4, 1)}
• 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}
– first element is always twice the second:
S = {(x, y) | x ÎD1, y ÎD2, and x = 2y}

8
Mathematical Definition of Relation
subexpert.com
• 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.

9
Examples - Attribute Domains
subexpert.com

10
Database Relations
• Relation schemasubexpert.com
– 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)}

• 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}

11
Properties of Relations
• subexpert.com
Relation name is distinct from all other relation names
in relational schema.
• Each cell of relation contains exactly one atomic
(single) value.
• 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.
• Each tuple is distinct; there are no duplicate tuples.
• Order of attributes has no significance.
• Order of tuples has no significance, theoretically.

12
Relational Keys
• Uniquely identifies each tuple in a relation
• Superkey subexpert.com
– An attribute, or set of attributes, that uniquely identifies a tuple within a
relation.

• Candidate Key
– Superkey (K) such that no proper subset is a superkey within the relation.
– Has two properties
• In each tuple of R, values of K uniquely identify that tuple (uniqueness).
• No proper subset of K has the uniqueness property (irreducibility).
• Composite key
• When a key consists of more than one attribute
• In our Example city value can determine several branch offices (for example,
London has two branch offices). This attribute cannot be a candidate key.
• On the other hand, since each branch office a unique branch number, then
given a branch number value, branchNo, we can determine at most one tuple,
so that branchNo is a candidate key.
13
Relational Keys
• Primary Key
subexpert.com
– Candidate key selected to identify tuples uniquely within relation.

• Alternate Keys
– Candidate keys that are not selected to be primary key.

• Foreign Key
– Attribute, or set of attributes, within one relation that matches
candidate key of some (possibly same) relation.
– When an attribute appears in more than one relation, its
appearance usually represents a relationship between tuples of the
two relations. For example, branchNo

14
Representing Relational Database Schemas
subexpert.com
• The common convention for representing a relation schema is to
give the name of the relation followed by the attribute names in
parentheses.

• Normally, the primary key is underlined.

• E.g.
– Branch (branchNo, street, city, postcode)
– Staff (staffNo, fName, lName, position, sex, DOB, salary, branchNo)
– PropertyForRent (propertyNo, street, city, postcode, type, rooms, rent,
ownerNo, staffNo,branchNo)
– Client (clientNo, fName, lName, telNo, prefType, maxRent)
– PrivateOwner (ownerNo, fName, lName, address, telNo)
– Viewing (clientNo, propertyNo, viewDate, comment)
– Registration (clientNo, branchNo, staffNo, dateJoined)

15
Integrity Constraints
• subexpert.com
Integrity constraints ensure that the data is accurate.
• Domain constraints
– Form restrictions on the set of values allowed for the attributes of
relations
• Integrity rules
– Constraints or restrictions that apply to all instances of the database
– Two principle rules are
• Entity integrity
• Referential integrity
• Multiplicity
• General constraints
• Null
– Represents value for an attribute that is currently unknown or not applicable for
tuple.
– Deals with incomplete or exceptional data.
– Represents the absence of a value and is not the same as zero or spaces, which
are values.

16
Integrity Constraints
• Base Relation subexpert.com
– Named relation corresponding to an entity in conceptual schema,
whose tuples are physically stored in database.

• Entity Integrity
– In a base relation, no attribute of a primary key can be null.

• Referential Integrity
– If foreign key exists in a relation, either foreign key value must
match a candidate key value of some tuple in its home relation or
foreign key value must be wholly null.

• General Constraints
– Additional rules specified by users or database administrators that
define or constrain some aspect of the enterprise.

17
Views
• subexpert.com
Dynamic result of one or more relational operations
operating on base relations to produce another
relation.

• A virtual relation that does not necessarily 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.

• Views are dynamic, meaning that changes made to


base relations that affect view attributes are
immediately reflected in the view.

18
Updating Views
subexpert.com
• All updates to a base relation should be
immediately reflected in all views that
reference that base relation.

• If view is updated, underlying base relation


should reflect change.

19
Purpose of Views
subexpert.com
• Provides powerful and flexible security
mechanism by hiding parts of database from
certain users.

• Permits users to access data in a customized way,


so that same data can be seen by different users
in different ways, at same time.

• Can simplify complex operations on base


relations.

20

You might also like