3. Introduction
Prof. K. Adisesha
3
ER model:
ER model stands for an Entity-Relationship model. It is a high-level data model.
➢ This model is used to define the data elements and relationship for a specified system.
➢ It develops a conceptual design for the database. It also develops a very simple and
easy to design view of data.
➢ In ER modeling, the database structure is portrayed as a diagram called an entity-
relationship diagram.
➢Example, Suppose we design a school database. In
this database, the student will be an entity with
attributes like address, name, id, age, etc.
4. E-R diagram
Prof. K. Adisesha
4
Components of E-R model:
ER-Diagram is a visual representation of data that describes how data is related to each
other.
➢ Entity
➢ Attribute
➢ Relationship
5. E-R diagram
Prof. K. Adisesha
5
Components of E-R model:
ER-Diagram is a visual representation of data that describes how data is related to each
other.
Entity:
✓ An Entity can be any object, place, person or class.
Attribute:
✓ An Attribute describes a property or characteristic of an entity.
✓ Example: Roll_No, Name and Birth date can be attributes of a student
Relationship:
✓ A relationship type is a meaningful association between entity types.
✓ Relationship types are represented on the E-R diagram by a series of lines.
6. E-R diagram
Prof. K. Adisesha
6
Different notations of E-R diagram:
ER-Diagram is a visual representation of data that describes how data is related to each
other.
➢ Different notations of E-R diagram:
❖ Entity: An entity is represented using rectangles.
❖ Attribute: Attributes are represented by means of eclipses.
❖ Relationship: Relationship is represented using diamonds shaped box.
7. E-R diagram
Prof. K. Adisesha
7
Different notations of E-R diagram:
Entity: An entity may be any object, class, person or place. In the ER diagram, an entity
can be represented as rectangles.
➢ Consider an organization as an example- manager, product, employee, department etc.
can be taken as an entity.
Weak Entity: An entity that depends on another entity called a weak entity. The weak
entity doesn't contain any key attribute of its own.
➢ The weak entity is represented by a double rectangle.
8. E-R diagram
Prof. K. Adisesha
8
Different notations of E-R diagram:
Attribute: The attribute is used to describe the property of an entity. Eclipse is used to
represent an attribute.
➢ For example, id, age, contact number, name, etc. can be attributes of a student.
➢ Different types of Attributes are:
❖ Key Attribute
❖ Composite Attribute
❖ Multivalued Attribute
❖ Derived Attribute
9. E-R diagram
Prof. K. Adisesha
9
Different notations of E-R diagram:
Key Attribute: The key attribute is used to represent the main characteristics of an entity. It
represents a primary key. The key attribute is represented by an ellipse with the text
underlined.
Composite Attribute: An attribute that composed of many other attributes is known as a
composite attribute. The composite attribute is represented by an ellipse, and those ellipses
are connected with an ellipse.
10. E-R diagram
Prof. K. Adisesha
10
Different notations of E-R diagram:
Multivalued Attribute: An attribute can have more than one value. These attributes are
known as a multivalued attribute. The double oval is used to represent multivalued
attribute.
➢ For example, a student can have more than one phone number.
Derived Attribute: An attribute that can be derived from other attribute is known as a
derived attribute. It can be represented by a dashed ellipse.
➢ For example, A person's age changes over time
and can be derived from another attribute like
Date of birth.
11. E-R diagram
Prof. K. Adisesha
11
Relationship:
A Relationship describes relations between entities. Relationship is represented using
diamonds shaped box.
➢ There are three types of relationship that exist between entities:
❖ Binary Relationship
❖ Recursive Relationship
❖ Ternary Relationship
12. E-R diagram
Prof. K. Adisesha
12
Binary Relationship:
It means relation between two entities.
➢ This is further divided into three types.
❖ One to One
❖ One to Many
❖ Many to Many
➢ One to One:
✓ This type of relationship is rarely seen in real world.
✓ The above example describes that one student can enroll only for one course and a
course will have only one Student. This is not what you will usually see in relationship.
13. E-R diagram
Prof. K. Adisesha
13
Binary Relationship:
➢ One to Many:
✓ It reflects business rule that one entity is associated with many number of same
entity.
✓ For example, Student enrolls for only one Course but a Course can have many
Students.
➢ Many to Many:
✓ It reflects business rule that many entity are associated with many number of same
entity.
✓ The above diagram represents that many students can enroll for more than one
course.
14. E-R diagram
Prof. K. Adisesha
14
Different notations of E-R diagram:
Database can be represented using the notations. In ER diagram, many notations are
used to express the cardinality.
➢ These notations are as follows:
15. Relational Keys
Prof. K. Adisesha
15
Keys used in database:
Keys play an important role in the relational database. It is used to uniquely identify any
record or row of data from the table.
➢ It is also used to establish and identify relationships between tables.
➢ Types of keys:
16. Relational Keys
Prof. K. Adisesha
16
Keys used in database:
➢ Primary key:
✓ It is a field in a table which uniquely identifies each row/record in a database table.
Primary keys must contain unique values.
✓ A primary key column cannot have NULL values.
✓ Ex: In the EMPLOYEE table, ID can be the primary key since it is unique for each
employee.
17. Relational Keys
Prof. K. Adisesha
17
Keys used in database:
➢ Candidate Key:
✓ When more than one or group of attributes serve as a unique identifier, they are
each called as candidate key.
✓ In the EMPLOYEE table, id is best suited for the primary key. The rest of the
attributes, like SSN, Passport_Number, License_Number, etc., are considered a
candidate key.
18. Relational Keys
Prof. K. Adisesha
18
Keys used in database:
➢ Super Key:
✓ Super key is an attribute set that can uniquely identify a tuple. A super key is a
superset of a candidate key.
✓ In the EMPLOYEE table, for(EMPLOEE_ID, EMPLOYEE_NAME), the name of
two employees can be the same, but their EMPLYEE_ID can't be the same. Hence,
this combination can also be a key.
19. Relational Keys
Prof. K. Adisesha
19
Keys used in database:
➢ Alternate Key:
✓ The alternate key of any table are those candidate keys, which are not currently
selected as the primary key. This is also known as secondary key.
✓ example, employee relation has two attributes, Employee_Id and PAN_No, that act
as candidate keys. In this relation, Employee_Id is chosen as the primary key, so the
other candidate key, PAN_No, acts as the Alternate key.
20. Relational Keys
Prof. K. Adisesha
20
Keys used in database:
➢ Foreign key:
✓ A key used to link two tables together is called a foreign key, also called as
referencing key.
✓ Foreign key is a field that matches the primary key column of another table.
✓ In the EMPLOYEE table, Department_Id is the foreign key, and both the tables are
related.
21. Relational Keys
Prof. K. Adisesha
21
Keys used in database:
➢ Composite key:
✓ Whenever a primary key consists of more than one attribute, it is known as a
composite key. This key is also known as Concatenated Key.
✓ in employee table, an employee may be assigned multiple roles, and an employee
may work on multiple projects simultaneously. So the primary key will be
composed of all three attributes, namely Emp_ID, Emp_role, and Proj_ID in
combination.
22. Integrity Constraints
Prof. K. Adisesha
22
Integrity Constraints:
Integrity constraints are pre-defined set of rules that are applied on the table
fields(columns) or relations to ensure that the overall validity, integrity, and consistency
of the data present in the database table is maintained.
➢ It is used to maintain the quality of information.
➢ It ensures that the data insertion, updating, and other processes have to be performed in
such a way that data integrity is not affected.
➢ Types of integrity constraints in relational data model:
❖ Domain Constraint
❖ Entity Constraint
❖ Referential Integrity Constraint
❖ Key Constraint
23. Integrity Constraints
Prof. K. Adisesha
23
Integrity Constraints Types:
Domain integrity constraint :
➢ Domain constraints can be defined as the definition of a valid set of values for an
attribute.
➢ The data type of domain includes string, character, integer, time, date, currency, etc.
The value of the attribute must be available in the corresponding domain.
ID NAME SEMESTER AGE
10001 PRAJWAL 2 19
10002 SUNNY 1 18
10003 SHAILU 3 A
24. Integrity Constraints
Prof. K. Adisesha
24
Integrity Constraints Types:
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.
ID NAME SEMESTER AGE
10001 PRAJWAL 2 19
10002 SUNNY 1 18
SHAILU 3 20
25. Integrity Constraints
Prof. K. Adisesha
25
Integrity Constraints Types:
Referential Integrity Constraints: A referential integrity constraint is specified between
two tables.
➢ In the Referential integrity constraints, if a foreign key in Table 1 refers to the Primary
Key of Table 2, then every value of the Foreign Key in Table 1 must be null or be
available in Table 2.
26. Integrity Constraints
Prof. K. Adisesha
26
Integrity Constraints Types:
Key constraints: Keys are the entity set that is used to identify an entity within its entity
set uniquely.
➢ An entity set can have multiple keys, but out of which one key will be the primary key.
A primary key can contain a unique and null value in the relational table..
ID NAME SEMESTER AGE
10001 PRAJWAL 2 19
10002 SUNNY 1 18
10002 SHAILU 3 20
27. Generalization
Prof. K. Adisesha
27
Generalization:
Generalization is a bottom-up approach in which two lower level entities combine to
form a higher level entity.
➢ In generalization, a number of entities are brought together into one generalized entity
based on their similar characteristics.
➢ For example, Student and Parent details can all be generalized as a group ‘Person’ as
Personal details.
28. Specialization
Prof. K. Adisesha
28
Specialization:
Specialization is a Top-down approach in which one higher level entity can be broken
down into two lower level entities.
➢ Specialization is the opposite of generalization.
➢ In specialization, a group of entities is divided into sub-groups based on their
characteristics.
➢ Take a group ‘Person’ for example. A person has name, date of birth, gender, etc.
Similarly, in a school database, persons can be specialized as teacher, student, or a staff,
based on what role they play in school as entities.
29. Aggregation
Prof. K. Adisesha
29
Aggregation:
In aggregation, the relation between two entities is treated as a single entity. In
aggregation, relationship with its corresponding entities is aggregated into a higher level
entity.
➢ Center entity offers the Course entity act as a single entity in the relationship which is in
a relationship with another entity visitor. If a visitor visits a coaching center then he will
enquiry about both Course and Center.
30. Aggregation
Prof. K. Adisesha
30
Aggregate function:
Aggregate functions in DBMS take multiple rows from the table and return a value
according to the query.
➢ Common aggregate functions include:
❖ Average (i.e., arithmetic mean)
❖ Count
❖ Maximum
❖ Median
❖ Minimum
❖ Mode
❖ Range
❖ Sum
31. ER diagram
Prof. K. Adisesha
31
Reduction of ER diagram to Table:
The database can be represented using the notations, and these notations can be reduced
to a collection of tables.
32. ER diagram
Prof. K. Adisesha
32
Reduction of ER diagram to Table:
Table structure for the given ER diagram is as below:
33. ER diagram
Prof. K. Adisesha
33
Reduction of ER diagram to Table:
Steps to convert Table structure from the given ER diagram is as below:
➢ Entity type becomes a table.
❖ In the given ER diagram, LECTURE, STUDENT, SUBJECT and COURSE forms
individual tables.
➢ All single-valued attribute becomes a column for the table.
❖ In the STUDENT entity, STUDENT_NAME and STUDENT_ID form the column of
STUDENT table. Similarly, COURSE_NAME and COURSE_ID form the column of
COURSE table and so on.
➢ A key attribute of the entity type represented by the primary key.
❖ In the given ER diagram, COURSE_ID, STUDENT_ID, SUBJECT_ID, and LECTURE_ID
are the key attribute of the entity.
34. ER diagram
Prof. K. Adisesha
34
Reduction of ER diagram to Table:
Steps to convert Table structure from the given ER diagram is as below:
➢ The multivalued attribute is represented by a separate table.
❖ In the student table, a hobby is a multivalued attribute. So it is not possible to represent
multiple values in a single column of STUDENT table. Hence we create a table
STUD_HOBBY with column name STUDENT_ID and HOBBY. Using both the column, we
create a composite key.
➢ Composite attribute represented by components.
❖ In the given ER diagram, student address is a composite attribute. It contains CITY, PIN,
DOOR#, STREET, and STATE. In the STUDENT table, these attributes can merge as an
individual column.
➢ Derived attributes are not considered in the table.
❖ In the STUDENT table, Age is the derived attribute. It can be calculated at any point of time
35. Relation Algebra
Prof. K. Adisesha
35
Relation Algebra:
Relational algebra is a procedural query language. It gives a step by step process to
obtain the result of the query. It uses operators to perform queries.
➢ Types of Relational operation:
36. Relation Algebra
Prof. K. Adisesha
36
Relation Algebra:
Relational algebra is a procedural query language that consists of a set of operations
that take one or more relations as input and result into a new relation as an output.
➢ The relational algebraic operations can be divided into:
❖ Basic set-oriented operations:
✓ Union, Set different, Cartesian product
❖ Relational-oriented operations:
✓ Selection, Projection, Division, Joins
37. Relation Algebra
Prof. K. Adisesha
37
Joins:
Joins in Database Management System are used in relational algebra and SQL to
join/combine more than one table to get some specific results out of those tables.
➢ A Join operation combines related tuples from different relations, if and only if a given
join condition is satisfied. It is denoted by ⋈.
➢ Different types of the JOINs in SQL:
❖ (INNER) JOIN
❖ LEFT (OUTER) JOIN
❖ RIGHT (OUTER) JOIN
❖ FULL (OUTER) JOIN
38. Relation Algebra
Prof. K. Adisesha
38
Joins:
Joins in Database Management System are used in relational algebra and SQL to
join/combine more than one table to get some specific results out of those tables.
➢ Different types of the JOINs in SQL:
❖ (INNER) JOIN: Returns records that have matching values in both tables
❖ LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records from
the right table
❖ RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched records
from the left table
❖ FULL (OUTER) JOIN: Returns all records when there is a match in either left or right table
39. Database Model
Prof. K. Adisesha
39
Normalization:
Normalization is a step by step process of removing the different kinds of redundancy
and anomaly one step at a time from the database.
➢ E.F Codd developed for the relation data model in 1970.
➢ Normalization rules are divided into following normal form:
40. Database Model
Prof. K. Adisesha
40
Normalization:
Normalization is a step by step process of removing the different kinds of redundancy
and anomaly one step at a time from the database.
41. Questions
Important Questions:
➢ Define the following database terms:
a. Data Model b. Tuple c. Domain d. Primary key e. Foreign key
➢ Write the difference between manual and electronic data processing.
➢ Explain any five applications of database.
➢ Briefly explain the data processing cycle.
➢ Write the difference between Hierarchical data model and network data model.
➢ What is normalization? Explain second normal form with an example.
➢ What is database model? Explain Hierarchical model.
➢ Explain 3-level DBMS architecture.
➢ .
Prof. K. Adisesha
41