Chapter 3 Relational Data Model(2)
Chapter 3 Relational Data Model(2)
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.
• In relational database, data and relations between them are organized into
tables.
• A table is a collection of records
4
Terminologies
• A relational data model represents data as a collection of
tables
• A table is also called a relation
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
Eg STUNDET(idNo,name,address,age,phone,gpa)
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.
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)
10
Database schema:
• is a set of relation schemas and a set of integrity constraints
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
For Example,
STUD_NO,
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
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
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
123456789
01 Bikash Dutta 234456678
31
Example
32
Key constraints or Uniqueness Constraints
33
Entity integrity constraints
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,
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…)
42
References
43