L7 CSC209 2.0 Database Management Systems
L7 CSC209 2.0 Database Management Systems
Presented By:
Surani Tissera(PhD)
Department of Computer Science
CSC 209 2.0 Database Management Systems
Slide 4-
2
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
Informal Definitions
● Informally, a relation looks like a table of values.
● The data elements in each row represent certain facts that correspond to
a
real-world entity or relationship
○ In the formal model, rows are called tuples
Example of a Relation
Slide 5-
4
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
Informal Definitions
● Key of a Relation:
○ Each row has a value of a data item (or set of items)
that uniquely identifies that row in the table
■Called the key
○ In the STUDENT table, SSN is the key
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
○dom(Cust-name) is varchar(25)
● The role these strings play in the CUSTOMER relation is that of the
name of a customer.
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
Definition Summary
Informal Terms Formal Terms
Table Relation
Column Header Attribute
All possible Column Domain
Values
Row Tuple
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
Characteristics Of Relations
● Ordering of tuples in a relation r(R):
○ The tuples are not considered to be ordered, even though they appear to be
in the tabular form.
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
Characteristics Of Relations
● Values in a tuple:
○ All values are considered atomic (indivisible).
○ Each value in a tuple must be from the domain of the attribute for that
column
■ If tuple t = <v1, v2, …, vn> is a tuple (row) in the relation state r of
R(A1, A2, …, An)
■ Then each vi must be a value from dom(Ai)
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
Characteristics Of Relations
● Notation:
○ We refer to component values of a tuple t by:
■ t[Ai] or t.Ai
■ This is the value vi of attribute Ai for tuple t
○ Similarly, t[Au, Av, ..., Aw] refers to the subtuple of t containing the values
of attributes Au, Av, ..., Aw, respectively in t
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
Key Constraints
● Superkey 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)
● Key of R:
○ A "minimal" superkey
○ That is, a key is a superkey K such that removal of any attribute from K results in a
set of attributes that is not a superkey (does not possess the superkey uniqueness
property)
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
size)
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
Entity Integrity
● Entity Integrity:
○ 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 primary key values are used to identify the individual
tuples.
■ t[PK] ≠ null for any tuple t in r(R)
■ If PK has several attributes, null is not allowed in any of these
attributes
○ Note: Other attributes of R may be constrained to disallow null values,
even though they are not members of the primary key.
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
Referential Integrity
● A constraint involving two relations
○ The previous constraints involve a single relation.
● Used to specify a relationship among tuples in two relations:
○ The referencing relation and the referenced relation.
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
Referential Integrity
● Tuples in the referencing relation R1 have attributes FK (called foreign key
attributes) 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 arc from R1.FK to R2.
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
○ Can also point the the primary key of the referenced relation for clarity
● Next slide shows the COMPANY relational schema diagram
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
● Each relation will have many tuples in its current relation state
● The relational database state is a union of all the individual relation states
● Whenever the database is changed, a new state arises
● Basic operations for changing the database:
○ INSERT a new tuple in a relation
○ DELETE an existing tuple from a relation
○ MODIFY an attribute of an existing tuple
● Next slide shows an example state for the COMPANY database
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
ICT 206 1.5 - Database Systems and Administration
Slide 5-
33
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
Slide 5-
38
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
Summary
● Presented Relational Model Concepts
○ Definitions
○ Characteristics of relations
● Discussed Relational Model Constraints and Relational Database Schemas
○ Domain constraints’
○ Key constraints
○ Entity integrity
○ Referential integrity
● Described the Relational Update Operations and Dealing with Constraint Violation
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
CSC 209 2.0 Database Management Systems
In-Class Exercise
(Taken from Exercise 5.15)
Consider the following relations for a database that keeps track of
student enrollment in courses and the books adopted for each course:
STUDENT(SSN, Name, Major, Bdate)
COURSE(Course#, Cname, Dept)
ENROLL(SSN, Course#, Quarter, Grade)
BOOK_ADOPTION(Course#, Quarter, Book_ISBN)
Draw a relational schema diagram specifying the foreign keys for this
schema.
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.
ICT 206 1.5 - Database Systems and Administration
This is a property of Department of Computer Science, Faculty of Applied Science, University of Sri Jayewardenepura.