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

Chapter 3 Relational Data Model(2)

Chapter 3 discusses the Relational Data Model, which organizes data into tables and was first introduced by Ted Codd in 1970. It covers key concepts such as relational schema, types of keys (including super, candidate, primary, alternate, and foreign keys), and various constraints that ensure data integrity. The chapter emphasizes the importance of these elements in managing and structuring relational databases effectively.

Uploaded by

fikadus794
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Chapter 3 Relational Data Model(2)

Chapter 3 discusses the Relational Data Model, which organizes data into tables and was first introduced by Ted Codd in 1970. It covers key concepts such as relational schema, types of keys (including super, candidate, primary, alternate, and foreign keys), and various constraints that ensure data integrity. The chapter emphasizes the importance of these elements in managing and structuring relational databases effectively.

Uploaded by

fikadus794
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

Chapter 3

Relational Data Model

1
Lesson 3 Topics
• Introduction to Relational Data Model
• Terminologies
• Types of Keys in Relational Model
• Characters of Relations
• Relational Model Constraints

2
Relational Data Model
• The relational database model is the most common model in industry today.

• First introduced by Ted Codd in 1970

• Uses the mathematical concept of relation

• In relational database, data and relations between them are organized into
tables.
• A table is a collection of records

• Each record in a table contains the same fields

• First Commercial implementations of relational data model:

Oracle DBMS, SQL/DS (IBM)


• The current popular RDMBS –SQL Server, MS-Access,
mysql, postgreSql, DB2 and informix (IBM) etc
3
• Standard for commercial RDBMS-SQL
(Structured Query language)

4
Terminologies
• A relational data model represents data as a collection of
tables
• A table is also called a relation

• Tables are further divided into columns and rows.

• Columns represent the attributes of an entity, while rows


represent the entities themselves.
• Each row in a table is called a tuple.

• Each column header is called an attribute or a field.

5
6
• In the student table, the columns represent attributes such as
name, date of birth and
• The rows represent individual students

7
Relational Schema:
• Describes a relation

• Made up of a relation name R and a list of attributes


A1,A2,A3,…,An.

Eg STUNDET(idNo,name,address,age,phone,gpa)

• A relational schema can also include data types of


attributes

STUNDET(idNo:intger,name:string,address :string,age:integ
er,phone:integer,gpa:real)
8
Domain- A set of atomic values that are allowed for
an attribute.

Eg: for the attribute name: The domain is the set of


strings that represent the name of persons
For the attribute age of employees the domain is values

between 20 and 70 years.

9
Degree or arity of a relation: The no of columns or attributes
in a relati onal schema.
Eg
STUNDET(idNo:intger,name:string,address :string,age:integer,phon
e:integer,gpa:real)

Degree of the STUDENT relati on is : 6


Cardinality: The number of rows or tuples in a table or in a relation

10
Database schema:
• is a set of relation schemas and a set of integrity constraints

Eg: For a company database, the database schema includes:


employee relation schema, project relation schema, department
relation schema , etc

Relation state (or relation instance)


• Set of tuples at a give time.

11
Entity:
A real world object with some properties which can be
easily identified is called an entity.

Attributes:
An attribute is a descriptive property or a
characteristics of an entity. Ex name, roll marks, etc.

12
13
Types of Keys in Relational Model

• Keys are very important part of Relational database

model. They are used to establish and identify

relationships between tables and also to uniquely

identify any record or row of data inside a table.


– Super key
– Candidate key,
– Primary,
– Alternate key and
– Foreign key 14
Super key
• The set of attributes that can uniquely identify a tuple is
within a table known as Super Key.

For Example,

STUD_NO,

(STUD_NO, STUD_NAME), phone etc.

A super key is a group of single or multiple keys that


identifies rows in a table. It supports NULL values.
STUD_NO SNAME ADDRESS PHONE
1 Shyam Delhi 123456789
2 Rakesh Kolkata 223365796
3 Suraj Delhi 175468965
15
Candidate Key: The minimal set of attributes that can uniquely
identify a tuple
• It is a minimal super key.
• It can contain NULL values.
• Every table must have at least a single candidate key.
• There can be more than one candidate key in a relationship.

For Example, STUD_NO or PHONE in STUDENT is a candiate key

STUD_NO SNAME ADDRESS PHONE

1 Shyam Delhi 123456789


2 Rakesh Kolkata 223365796
3 Suraj Delhi 175468965
16
Table STUDENT_COURSE

STUD_NO TEACHER_NO COURSE_NO


1 001 C001
2 056 C005

{STUD_NO, COURSE_NO} is a composite


candidate key for relation STUDENT_COURSE.

17
Primary Key:
• There can be more than one candidate key in relation out of which
one can be chosen as the primary key.
• For Example, STUD_NO, as well as STUD_PHONE, are candidate
keys for relation STUDENT but STUD_NO can be chosen as the
primary key (only one out of many candidate keys).
• 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.

18
Relation between Primary Key, Candidate Key, and
Super Key

19
Alternate Key:
• The candidate key other than the primary key
is called an alternate key.
• It is a secondary key.

20
Composite Key
• Key that consists of two or more attributes that uniquely
identify any record in a table is called Composite key.
• But the attributes which together form the Composite key are
not a key independently or individually.

21
foreign key
• A foreign key is a column or columns of data in one table that
refers to the unique data values -- often the primary key data --
in another table.
• Foreign keys link together two or more tables in a
relational database.
• can only take the values which are present as values of some
other attribute
• It is a key it acts as a primary key in one table

22
Example:
Student Department
idNo firstName age dno dnao dname

23
Non prime attributes

• Attributes of a relation which do not exist in any of the

possible candidate keys of the relation

24
Characters of Relations
1. The data represented in this model is in the form of
two dimensional table called relation.
2. An entity is represented by a tuple in a row.
3. The rows of a table are distinct.
4. Each column of the table is assigned distinct heading
called name of the attribute.
5. In each column, data items are of similar type.
• All values in a column must conform to the same data
format , For example if the attribute is assigned an
integre data format, all values in the column representing
that attribute must be integers.

25
Characters of Relations
6. Order of tuples within a relation
a relation is a set of tuples

R={t1,t2,t3,..tn}
Elements of a set do not follow any order.
Tuples in a relation need not have any order.
The Sequence of Rows is Insignificant

26
7. The Sequence of Columns is Insignificant
• The ordering of the columns is immaterial

8. Values and nulls in a tuple


– Each value in a tuple is atomic.Each row/column intersection represents a single
data value
– in a relational table are not repeating group or arrays

• Null Value-unknown or not applicable


Eg: for the attribute home_phone some students may not have a home phone.

9.Each column has a specific range of values known as the attribute


domain
10. Each Column Has a Unique Name
11.Each table must have an attribute or a combination of attributes
27
Relational Model Constraints
Integrity Constraints
• Constraints are the restrictions on the actual
values in a database.
• When we have to insert into the database, we
should impose some constraints on those values
• A constraint is used to guard against accidental
damage to the database.

28
Types of Constraints on the relational
database:
1. Domain constraints
2. Key constraints or Uniqueness Constraints
3. Entity Integrity Constraints
4. Referential Integrity Constraints

29
Domain Constraints:
• Limit the range of domain an attribute values on.
• Every domain must contain atomic values(smallest indivisible
units) which means composite and multi-valued attributes are
not allowed.
• We perform a datatype check here, which means when we
assign a data type to a column we limit the values that it can
contain. Eg. If we assign the datatype of attribute age as int, we
can’t give it values other than int datatype.

30
Example

EID Name Phone

123456789
01 Bikash Dutta 234456678

• In the above relation, Name is a composite attribute and Phone


is a multi-values attribute, so it is violating domain constraint.

31
Example

32
Key constraints or Uniqueness Constraints

• Tuple Uniqueness constraint specifies that all the tuples must


be necessarily unique in any relation.

• Key constraint specifies that in any relation-

• All the values of primary key must be unique.


• The value of primary key must not be null.

33
Entity integrity constraints

• The entity integrity constraint states that primary key

value can't be null.

• This is because the primary key value is used to

identify individual rows in relation and if the primary


key has a null value, then we can't identify those rows.

• A table can contain a null value other than the primary

key field.

34
Example:

35
Referential Integrity Constraint-
• This constraint is enforced when a foreign key references the
primary key of a relation.
• It specifies that all the values taken by the foreign key must either
be available in the relation of the primary key or be null.

36
37
Student Table
Department Table
STU_ID Name Dept_no
S001 Akshay D10 Dept_no Dept_name
S002 Abhishek D10 D10 ASET
D11 ALS
S003 Shashank D11 D12 ASFL
S004 Rahul D14 D13 ASHS

Here,

• The relation ‘Student’ does not satisfy the referential


integrity constraint.
• This is because in relation ‘Department’, no value of
primary key specifies department no. 14.
• Thus, referential integrity constraint is violated.
38
39
Lesson Summary

• The relational database model is the most common


model in industry today.
• First introduced by Ted Codd in 1970
• Uses the mathematical concept of relation
• A relational data model represents data as a
collection of tables
• Relational Schema is the describes a relation

40
Lesson Summary(Cont…)
• Domain- A set of atomic values that are allowed for an
attribute.
• Five type of Keys:
• Super key
• Candidate key,
• Primary,
• Alternate key and
• Foreign key

41
Lesson Summary(Cont…)

• Relational Model Constraints


1. Domain constraints
2. Key constraints or Uniqueness Constraints
3. Entity Integrity Constraints
4. Referential Integrity Constraints

42
References

Elmasri & Navathe, “Fundamentals of database


systems”, 4th ed

43

You might also like