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

Class 7

The document discusses key concepts in relational databases including relations, tuples, attributes, domains, keys, and how a relational model represents data using sets and relationships between tuples rather than pointers. It provides examples of relations and describes properties like cardinality and degrees. The document also defines terms used in relational databases.

Uploaded by

BHAVYA KALYANI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Class 7

The document discusses key concepts in relational databases including relations, tuples, attributes, domains, keys, and how a relational model represents data using sets and relationships between tuples rather than pointers. It provides examples of relations and describes properties like cardinality and degrees. The document also defines terms used in relational databases.

Uploaded by

BHAVYA KALYANI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

CS F212: Database Systems

Today’s Class
Relational Model
 Basic Concepts
 Keys

CS F212 Database Systems 1


Relational Model Concepts
• Relational Model of data is based on the concept of
RELATION
• A Relation is a Mathematical concept based on idea of
SETS
• The strength of the relational approach to data
management comes from the formal foundation provided
by the theory of relations

CS F212 Database Systems 2


Relational Model Concepts
The model was first proposed by Dr. E.F. Codd of IBM in
1970 in the following paper:
"A Relational Model for Large Shared Data Banks," Comm
unications of the ACM, June 1970.
The above paper caused a major revolution in the field of Database
management and earned Ted Codd the coveted ACM Turing Award
in 1981

CS F212 Database Systems 3


Some Terms
• Table  Relation
• Row or Record  Tuple
• Column or Field  Attribute
• No. of Rows  Cardinality
• No. of Columns  Degree or Arity
• Unique Identifier  Primary key
• Pool of Legal Values  Domain

CS F212 Database Systems 4


Example Relation

Cardinality = 5
Degree = 7
Primary Key is SSN

CS F212 Database Systems 5


Relational Database: Definitions
• Relational database: a set of relations
• Relation: made up of 2 parts:
• Instance : a table, with rows and columns.
#Rows = cardinality, #fields = degree / arity.
• Schema : specifies name of relation, plus name and type of each
column.
• e.g. Students(sid: string, name: string, login: string,age: integer, gpa: real).
• Can think of a relation as a set of rows or tuples (i.e., all rows
are distinct).
An Example Relation
Relation Name/Table Name Attributes/Columns (collectively as a schema)

STUDENT
Name Student-id Age CGPA
Chan Kin Ho 99223367 23 8.19

Tuples/Rows
Lam Wai Kin 96882145 17 10.00
Man Ko Yee 96452165 22 8.75
Lee Chin Cheung 96154292 16 10.00
Alvin Lam 96520934 15 9.65

 Cardinality = 5, degree = 4, all rows distinct


Another Relation Example

enrollment (studentName, rollNumber, courseNo, sectionNo)

enrollment
Domains & Data Types
• Significance of domains
• Domain-constrained comparisons
Select …..
From P, SP
Where P.P# = SP.P#

Select …..
From P, SP
Where P.weight = SP.qty
Both are valid queries in SQL, but second one makes no sense!!
• Domains implemented as Data-Types?

CS F212 Database Systems 9


Relational Systems
• In relational systems, the DB is perceived by the user
as relations & nothing else
• Relations are only logical structures
• At the physical level, the system is free to store the
data in any way it likes – using sequential files,
indexing, hashing…
• Provided it can map stored representations to
relations

CS F212 Database Systems 10


Relational Systems
• Consider the relations:
Dept(dept#, dname, budget)
D1 MKTNG 10M
D2 DEV 12M
D3 RES 5M

Emp(emp#, ename, dept#, salary)


E1 LOPEZ D1 40K
There is a connection between tuples E1 & D1. The connection is represented,
not by a pointer, but by the occurrence of value D1 in E1.
In non-relational systems, such information is typically represented by some
kind of pointer that is visible to the user.

CS F212 Database Systems 11


Relational Systems
• In relational systems, there are no pointers at the logical
level
• Pointers will be there at the physical level
• Physical storage details are concealed from the user in
relational systems

CS F212 Database Systems 12


Properties of Relations
• There are no duplicate tuples
• Body of a relation is a mathematical set
• Tuples are unordered, top to bottom
• Body of a relation is a mathematical set
• No such thing as fifth tuple, next tuple ..
• No concept of positional addressing
• Attributes are unordered, left to right
• Heading of a relation is a mathematical set
• No concept of positional addressing
• All attribute values are atomic
• Normalized (1st Normal Form)

CS F212 Database Systems 13


Types of Relations
• Base Relations
• The original (given) relations
• Derived Relations
• Relations obtained from base relations
• Views
• “Virtual” derived relation
• Only definition is stored in the catalog
• Definition executed at run-time
• Snapshots
• “Real” derived relation
• Query Result
• Unnamed derived relation

CS F212 Database Systems 14


Some Formal Definitions
A relation is denoted by: R(A1, A2, ..., An)
 STUDENT(Name, Student-id, Age, CGA)
Degree of a relation: the number of attributes n in the relation.
Tuple t of R(A1, A2, ..., An): An ordered set of values <v1,v2,...,vn>
where each vi is an element of dom(Ai).
Relation instance r(R): A set of tuples in R
r(R) = {t1, t2, ..., tm}, or alternatively

r(R)  dom(A1)  dom(A2)  ...  dom(An)


Relation and Cartesian Product
A relation is any subset of the Cartesian product of domains of
values
Example: Let Dom(Name) = { Lee, Cheung }
Dom(Grade) = { A, B, C }
Then the Cartesian product of the domains is
Dom(Name)  Dom(Grade) = { Lee, A, Lee, B , Lee, C,
Cheung, A, Cheung, B, Cheung C }
A relation StudentGrade (Name, Grade) can be defined as any
subset of the Cartesian product Dom(Name)  Dom(Grade)
r(StudentGrade) = { Lee, A, Cheung C }  Dom(Name)  Dom(Grade)
Characteristics of Relations
Tuples in a relation are not considered to be ordered,
even though they appear to be in a tabular form.
(Recall that a relation is a set of tuples.)
Ordering of attributes in a relation schema R are
significant.
Values in a tuple: All values are considered atomic.
(Recall that a domain is a set of atomic values.) A
special null value is used to represent values that are
unknown or inapplicable to certain tuples or does not
exist.
Keys
• Let K  R (I.e., K is a set of attributes which is a subset of the
schema of R)
• K is a superkey of R if K can identify a unique tuple in a given
relation r(R)
Customer(CusNo, Name, Address, …)
where customers have unique customer numbers and
unique names.
Possible superkeys: CusNo
{CusNo, Name}
{CusNo, Name, Address}
plus many others
K is a candidate key if K is minimal
There are two candidate keys: CusNo and Name
Every relation is guarantee to (must) have at least one key. Why?
Key(Candidate key)
• A key can not be determined from any particular instance
data
• it is an intrinsic property of the schema
• it can only be determined from the meaning of attributes
• A relation can have more than one key.
• Superkey: A set of attributes that contains any key as a
subset.
• A key can also be defined as a minimal superkey
• Primary Key: One of the candidate keys chosen for indexing
purposes ( More details later…)

You might also like