0% found this document useful (0 votes)
8 views41 pages

L3 RelationalModel

The document outlines a lecture on the Relational Model in Database Management Systems, covering topics such as the structure of relational databases, definitions of relations, instances, and schemas, as well as keys including superkeys, candidate keys, primary keys, and foreign keys. It emphasizes the importance of database schema versus instance, atomicity of attributes, and referential integrity constraints. The lecture is part of a course offered by the Department of CSE at Amrita School of Computing, Coimbatore.
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)
8 views41 pages

L3 RelationalModel

The document outlines a lecture on the Relational Model in Database Management Systems, covering topics such as the structure of relational databases, definitions of relations, instances, and schemas, as well as keys including superkeys, candidate keys, primary keys, and foreign keys. It emphasizes the importance of database schema versus instance, atomicity of attributes, and referential integrity constraints. The lecture is part of a course offered by the Department of CSE at Amrita School of Computing, Coimbatore.
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/ 41

19CSE202 Database Management Systems

Lecture 3 Relational Model


B.Tech /II Year CSE/III Semester L T P C 3-0-3-4

DBMS Team
Bindu K R
Ms. Anisha Radhakrishnan
Ms. Uma J
Mr. Chakravartula Raghavachari
Department of CSE
Amrita School of Computing
Syllabus
19CSE202

2
19CSE202 DBMS Dept of CSE, Amrita School of Computing, Coimbatore
Brief Recap of Previous Lecture

❑ Database Abstraction
❑ Instances and Schemas
❑ Data Models
❑ Database Users

3
19CSE202 DBMS Dept of CSE, Amrita School of Computing, Coimbatore
Today’s Lecture

❑ Structure of Relational Databases


❑ Keys
❑ Schema Diagrams

4
19CSE202 DBMS Dept of CSE, Amrita School of Computing, Coimbatore
Introduction

● Relational data model is the commercial data model


for today’s applications.

● It is simple and ease of use for programmer


compared to other models.

19CSE202 DBMS Dept of CSE, Amrita School of Computing, Coimbatore 5


Relational Database: Definitions
❑ Relational database: a set of relations
❑ Relation: made up of 2 parts:
❑ 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)
❑ Instance : a table, with rows and columns.
➢ #Rows = cardinality
➢ #fields = degree / arity
❑ Can think of a relation as a set of rows or tuples (i.e., all rows are distinct).

❑ Columns (attributes) are single-valued/atomic.

6
19CSE202 DBMS Dept of CSE, Amrita School of Computing, Coimbatore
Relational Database: Definitions
sid name login age gpa
53666 Jones jones@cs 18 3.4
53688 Smith smith@eecs 18 3.2
53650 Smith smith@math 19 3.8

❑ #Rows = cardinality=?

❑ #fields = degree / arity=?

19CSE202 DBMS Dept of CSE, Amrita School of Computing, Coimbatore 7


Relational Database: Definitions
sid name login age gpa
53666 Jones jones@cs 18 3.4
53688 Smith smith@eecs 18 3.2
53650 Smith smith@math 19 3.8

❑ #Rows = cardinality=3
❑ #fields = degree / arity=5
❑ All rows are distinct

19CSE202 DBMS Dept of CSE, Amrita School of Computing, Coimbatore 8


Structure of Relational Model attributes
(or columns)

tuples
(or rows)
❑ Relational DB is a collection of Tables
or Relation.
❑ E.g. Instructor Table.

❑ There are four columns/attributes

❑ Each row is storing the values for


❑ ID, name, dept_name and salary of an
Instructor Table. Instructor.
19CSE202 DBMS Dept of CSE, Amrita School
of Computing, Coimbatore ❑ Each row is uniquely identified by ID. 9
• Another Example - Refer the Course Table.

• Course Table/Relation
❑ Four columns/attributes

❑ Each row is storing the values for


❑ course_id, title, dept_name and credits of a
course.

❑ Each course is uniquely identified by its


course_id.

19CSE202 DBMS Dept of CSE, Amrita School of Computing, Coimbatore 10


❑ Prereq
❑ Two columns/Attributes

❑ In Each row, the second course is the prerequisite


course for the first course.

❑ Thus, each row indicates two course are related.

❑ Similarly, in Instructor table, ID is related to name,


dept_name and Salary of an instructor.

❑ and in course table the course_ide is related to title,


dept_name and credit.
19CSE202 DBMS Dept of CSE, Amrita School of Computing, Coimbatore 11
Relational Model
• In general, table represents ❑ In Mathematics …
relationship among set of values. ❑ Tuple is a sequence of values.
❑ A relationship between n values is
• Relation/Table is a collection of represented as and n-tuple of values.
relationships.
❑ In Relational Model …
• ‘Table’ in Database design is similar ❑ Relation refers to a table.
to ‘relation’ in Mathematics…. ❑ Tuple refers to a row.
• Thus the term ‘Relational Model’. ❑ Attribute refers to a column.

19CSE202 DBMS Dept of CSE, Amrita School of Computing, 12


Relation Instance
❑ Refers to specific instance of a relation.

❑ Refer the Instructor relation instance, has 12


rows corresponding to 12 instructors.

❑ The order in which the row are arranged is


irrelevant.
❑ It can be sorted or unsorted.

❑ Both the instances in right side are the same.

Dept. of CSE., Amrita School of Engineering, Coimbatore 13


Concepts underlying Relational Model - domain
● Domain of salary – Set of salary of instructors.
● The set of allowed values for ● Domain of name – Set of names of instructors.
each attribute is called the
domain of the attribute. ● salary = {65000, 900000, 40000, 95000,
60000….80000}

● Each element in the domain a value for the attribute.

● 40000 is a value for the salary attribute.

Dept. of CSE., Amrita School of Engineering, Coimbatore 14


Concepts underlying Relational Model - Atomic
● Suppose we have ‘Phone-Number’
attribute in instructor relation, and
● For each relation (r), the domain of all allows multiple phone numbers for each
attributes of r be atomic. instructor,

● that is, indivisible. ● A sample domain of ‘Phone-Number’


● ={(0422-2685000,+91-8967563421),
● (8934765478), (1278347865, 0433-
● salary = {65000, 900000, 40000,
95000, 60000….80000} 783456)……}

● Is salary attribute atomic? ● First and third elements of this domain


has two phone numbers, hence it is non-
● Answer: yes. Why? atomic domain.
15
19CSE202 DBMS Dept of CSE, Amrita School of Computing, Coimbatore
Concepts underlying Relational Model - Atomic
❑ A sample domain of ‘Phone-Number’
{0422-2685000, 0433-783456, +91-8967452312}
❑ Is it Atomic domain?
Answer : No..
❑ Why? – each phone number is divisible – country code, city code and phone number.

❑ A sample domain of ‘Phone-Number’


❑ {3456789023, 3948576819, 7829345678}

❑ Is it Atomic domain?
Answer: Yes
❑ Why? – each element in this domain is single value ie., indivisible.

19CSE202 DBMS Dept of CSE, Amrita School of Computing, Coimbatore 16


Concepts underlying Relational Model - NULL

❑ The special value null is a member of every domain.


Indicated that the value is “unknown” or does not ❑ If an instructor does not have
exist. phone, the value for his phone-
number attributed to be stored
❑ The null value causes complications at the time of ‘null’
accessing the data from database, hence use of null
to be restricted.

17
Concepts underlying Relational Model -
Database schema Vs Database Instance. Database Instance

● Database Schema – the logical design of the database.

● Database Instance – the content of the database at an


instance of time.

Database Schema

18
Concepts underlying Relational Model -
relation Schema Vs relation instance
Relation Schemas Relation Instance

19CSE202 DBMS Dept of CSE, Amrita School of Computing,


Coimbatore 19
Concepts underlying Relational Model -
relation schema & instance…

● int marks [5]; ----- Variable


● marks[ ]=[78, 93, 90, 89, 83] ----- values

● Instance – changes.
● Schema – does not.

20
Let us proceed further with University Database

21
University Database – Relation Schemas

22
University Database – Relation Instances department
instructor course prerequisite

Instructor is related to department by


dept_name attribute.
section teaches

Instructor is related to sections by


course_id, sec_id and semester and the
association is stored in a new relation
teaches.


Dept. of CSE., Amrita School of Engineering, Coimbatore 23
Relation Schema and Instance
● If A1, A2, …, An are attributes

● R = (A1, A2, …, An ) is a relation schema


Example:
instructor = (ID, name, dept_name, salary)

● Formally, given sets D1, D2, …. Dn which are the domains A1, A2, …, An, 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

Dept. of CSE., Amrita School of Engineering, Coimbatore 24


❑ Structure of Relational
Databases
❑ Keys
❑ Schema Diagrams

19CSE202 DBMS Dept of CSE, Amrita School of Computing, Coimbatore 25


Keys
● No two relations in a relation is allowed to have same values in all the attributes.
Roll Number Name
CB.EN.U4CSE18201 AADURU VENKATA HEMA ABHINAV.
CB.EN.U4CSE18202 S.AAKASH MUTHIAH.
CB.EN.U4CSE18203 ABISHEK VASANTHAN A S.
CB.EN.U4CSE18204 M. S. ADARSH.
CB.EN.U4CSE18205 ADITHI NARAYAN.
CB.EN.U4CSE18206 AMBATI NAGA SREEHARSHA REDDY.

● Tuples with in a given relation to be distinguished, by the values of the attributes.

❑ Super Key
❑ Candidate Key
❑ Primary Key
❑ Foreign Key
Dept. of CSE., Amrita School of Engineering, Coimbatore 26
Superkey
❑ Let K  R
❑ K is a superkey of R if values for K are
sufficient to identify a unique tuple of each
possible relation r(R)

❑ Example: {ID} and {ID, name} are both superkeys


of instructor.
Let R denote the set of attributes in the schema of
❑ {name} is not a superkey, because more relation r.
instructors may have same name. For a subset of K of R is a superkey for r no distinct
tuples have the same values for all attributes in K.
i.e. If t1 and t2 are in r and t1<> t2, t1.K<>t2.K

19CSE202 DBMS Dept of CSE, Amrita School of Computing, Coimbatore 27


Candidate Key
❑ A superkey may have extraneous attribtute.
❑ Eg. In {ID, name}, name is extraneous.

❑ Superkey for which no proper subset is a superkey


is the candidate key.
❑ Superkey K is a candidate key if K is minimal
Example: {ID} is a candidate key for Instructor, but
not {ID, name}.

Many candidate keys for a relation


Eg. {ID} and {name, dept_name} for instructor.

Dept. of CSE., Amrita School of Engineering, Coimbatore 28


Entity Integrity- Primary key
❑ Several distinct set of attributes could serve
as candidate keys.

❑ The candidate key which is primarily chosen by


the database designer is the primary key.
{ID} in instructor is the primary key

19CSE202 DBMS Dept of CSE, Amrita School of Computing, Coimbatore 29


Entity Integrity -Primary Key
● Must be chose with care.

● Their attribute values are never or very rarely changed.


Eg. RollNumber.

● The primary key of a relation to be listed before other


attributes.
Refer the department relation.

19CSE202 DBMS Dept of CSE, Amrita School of Computing, Coimbatore 30


Referential Integrity -Foreign Keys
❑ A relation, say r1, may include among its attributed the
primary key of another relation, say r2.

❑ This attribute is called as foreign key from r1, referencing to


r2.

❑ The relation r1 is called as the referencing relation and r2 is


called the referenced relation.

❑ The foreign key forms a dependency between r1 and r2.

❑ Eg. dept_name attribute, from instructor relation to


department relation.

19CSE202 DBMS Dept of CSE, Amrita School of Computing, Coimbatore 31


19CSE202 DBMS Dept of CSE, Amrita School of Computing, Coimbatore 32
Referential Integrity Constraints- Foreign Key
section

❑ If a section exists for a course, it must be taught by at least one


instructor.
❑ However, it could possibly be taught by more than one instructor…..This
is a constraint.

❑ To enforce above constraint,


❑ we require that if a particular (course_id, sec_id, semester, year)
combination appears in section
❑ then the same combination must appears in teaches. ( Looks Like Foreign
key from section to teaches ).
❑ However this set of value is not form a primary key for teaches, since
more than one instructor may teach one such section.
❑ So we can not set foreign key from section to teaches
❑ (however we can define from teaches to section … why?)

teaches
19CSE202 DBMS Dept of CSE, Amrita School of Computing, Coimbatore 33
Referential Integrity Constraints
❑ The constraint from section to teaches is an example of a referential integrity constraint.

❑ A referential integrity constraint requires that the value appearing in the specified attributes of any
tuple in the referencing relation also appears in specified attributes of at least one tuple in the
referenced relation.

❑ Example: (Refer relations in the previous slide)

❑ section Referencing teaches by (course_id, sec_id, semester, year)

❑ section is referencing relation


❑ teaches is referenced relation

19CSE202 DBMS Dept of CSE, Amrita School of Computing, Coimbatore 34


● Contents

○ Structure of Relational Databases

○ Keys

○ Schema Diagrams

○ Relational Query Languages

○ Relational Operations

19CSE202 DBMS Dept of CSE, Amrita School of Computing, Coimbatore 35


Schema Diagram
● The database schema and its keys can be visualized in Schema Diagram.

36
Schema Diagram
● The database schema and its keys can be visualized in Schema Diagram.

Company database

37
Summary
❑ Structure of Relational Databases

❑ Keys

❑ Schema Diagrams

Dept. of CSE., Amrita School of Computing, Coimbatore 38


Next Lecture
❑ Relational Query Languages

❑ Relational Algebra

Dept. of CSE., Amrita School of Engineering, Coimbatore 39


References

⮚ https://docs.oracle.com/en/database/oracle/oracle-
database/20/newft/new-features.html
⮚ https://www.pda.org/scientific-and-regulatory-
affairs/regulatory-resources/data-integrity
⮚ https://www.digipay.guru/blog/all-you-need-to-know-
about-agency-banking/
⮚ https://md.ekstrandom.net/teaching/cs4332-f15.pdf
⮚ https://https://bit.ly/31eE2Ar
⮚ https://ipronline.com/oracle-the-pioneers-of-the-software-
world/
40
Thank You

Happy to answer any questions ! ! !

41

You might also like